Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Detect what caused the onPause

Tags:

android

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

like image 323
Bex Avatar asked May 24 '11 12:05

Bex


1 Answers

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

like image 79
Varun Avatar answered Nov 02 '22 09:11

Varun