I am not sure if there is a better way of doing this but I want to detect somehow what caused the application to pause.
On one particular activity that displays a tracking map if the user click back or home I want to stop GPS but if the screen goes off I want to keep the gps running I am also using a wake lock so it doesn't sleep (yes I know this probably should be in a service, but that will be v2 I'm running out of time!)
I am overriding when the back button is pressed
@Override
public void onBackPressed() {
wl.release();
this.mMyLocationOverlay.disableMyLocation();
this.mMyLocationOverlay.disableCompass();
if (mLocManager != null) {
mLocManager.removeUpdates(mLocListener);
}
super.onBackPressed();
}
but I can't find a way of doing the same for home.
Can anyone help?
Bex
in the onPause()
you can call isFinishing()
to know if the activity is finishing for whatever may be the reason or simply getting paused. See the doc here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With