0

Is there any way to identify what the next activity is going to be when onPause() is invoked.

I need to know because when the next activity is not one from my own application then I need to perform certain clean up that I don't want to perform when moving to an activity within my own application. I know I can set some sort of flag when I do the startActivity() in my application but I wondered if there is a built-in way to get it.

dd619
  • 5,910
  • 8
  • 35
  • 60
theblitz
  • 6,683
  • 16
  • 60
  • 114
  • I guess you can't. There isn't such provision so far. Your only way is to manage in your own way, as you know your app well. – Avinazz Jan 27 '13 at 09:20

1 Answers1

0

There is no way to guess which other activity got the focus. I implemented for something like that an Application class where all activities called a custom suspend function which waited for a resume call for 10 seconds. If no resume call was make by any activity my app knew that it had to shutdown and exited.

public ExampleApp extends Application {
    boolean shutdown;

    public void suspend() {
       shutdown=true;
       voodooFunctionToInvokeCallback10SeondsDelayed();
    }

    public void resume() {
       shutdown=false;
    }

    public void callback() {
        if(shutdown) {
            // shutdown code
        }
    }
}

public MyActivity extends Activity {
    public void onResume() {
        ((ExampleApp)getApplicationContext()).resume();
    }

    public void onPause() {
        ((ExampleApp)getApplicationContext()).suspend();
    }
}
rekire
  • 47,260
  • 30
  • 167
  • 264