我从这里Dev guide了解了 android 活动的生命周期。现在我对代码的哪一部分驻留在哪个方法中感到困惑,例如 onCreate、onStart、onResume、onRestart、onPause、onResume、onStop 和 onDestroy。你能帮我把它们放在正确的地方吗?即使应用程序最小化,跟踪也应该继续。我有以下代码。
public class MainActivity extends FragmentActivity implements LocationListener {
//List of user defined variables
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*for now i have kept everything in onCreate method
* i have start and stop button to start the tracking and stop the tracking and show the distance of travel
1. Checking whether GPS is on or OFF
2. button = (ImageButton) findViewById(R.id.myButton);
3. Code to load the Google map
4. Now specified what start and stop button does.
i. when i press start button it starts overlaying the path in the map and calculate distance travelled so far
ii. when i press stop button it stops tracking and shows the details of final result in next activity.
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 2, this);
*/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
//i hace code for tracking and overlaying here
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}