Search code examples
androidandroid-lifecycleonresumeonpause

Android Life Cycles — Why can't onResume() be called in onPause(){ }?


This question is entirely theoretical. I don't see any practical application, just for understanding, but...

I'm trying to figure out a way to break the Life Cycle system to force my app to be Active and Visible at all times (like even when the home button is pressed) so I'm calling onResume() in onPause() and onRestart() in onStop() etc..

I'd expect the app to restart when I press the home button but obviously the Android OS is smarter than I. What is blocking the app from restarting itself? Is there a way around it?


Solution

  • I think the better way would be to call:

    startActivity(new Intent(this, YourActivity.class));
    finish();
    

    inside onPause() (but all of these are pretty bad ideas)