I'd like to test the case of my app being killed and restarting in a non main activity pretending to the user that the app was simply resumed. Anyone know how to do this? None of the ideas I've found work as they all kill the app which then resumes at the main activity.
问题:
回答1:
I actually found this more convenient. Your app is killed and restarted in the previous activity, so just add a debug button to call this:
System.exit(0);
And if you want to restart in the current activity, just start another activity then immediately call this.
回答2:
If you have a ics phone (or in the emulator) just activate
don't keep activities
option.
From the doc:
Tells the system to destroy an activity as soon as it is stopped (as if Android had to reclaim memory). This is very useful for testing the onSaveInstanceState(Bundle) / onCreate(android.os.Bundle) code path, which would otherwise be difficult to force. Choosing this option will probably reveal a number of problems in your application due to not saving state. For more information about saving an activity's state, see the Activities document.