Question

Is there some way to "kill" my app when the user goes home, clicking the icon does not bring the app back after pressing home, or turning the screen off. I have to re-run the app in eclipse to get it to come forward.

Was it helpful?

Solution

You shouldn't do that. Instead implement onStart and onResume. Please read this thread for more information.

OTHER TIPS

Try these two ways.....

- Use System.exit(0) at the onDestroy()method of the Activity.

- You can use finish() method on the onDestroy() method of the Activity

It's not clear what you're trying to do, or what's going wrong. In general, there should be no problem resuming or restarting your app when the user goes home and then back to your app.

Could it be that your code is crashing when onCreate() is called with a non-null argument?

In general, your code flow should be:

onCreate(Bundle savedstate): If savedstate is null, your activity is starting from scratch. If non-null, it's being restarted after having been killed previously. The savedstate bundle should contain enough information to allow your activity to pick up where it left off.

onStart(): Activity is about to appear on the screen. I tend not to bother implementing this.

onResume(): Activity is about to start accepting input from the user. This is a good time to enable gps, sensors, background threads, or whatever else might be consuming resources. If none of the above applies, then I don't bother implementing this.

onSaveInstanceState(savedstate): Your activity may be going away and it may be killed soon. You MUST save enough information into the savedstate bundle to allow your app to be restarted later.

onPause(): Your activity is about to become inactive. Now is the time to shut down anything you started in onResume(). IMPORTANT: this may be the last call you receive before your app is killed, so now is the time to save any user preferences or other long-term state.

onStop(): Your activity is going off-screen. There is no guarantee that this will actually be called. For this reason, I rarely bother to implement this.

onDestroy(): Your activity is about to go away. Shut down anything you started in onCreate(). There is no guarantee that this will actually be called.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top