2

The behaviour Im seeing is:

If you use "dont keep activities" the memory of the activity will always be destroyed and it will be recreated from scratch with the data from the Intent and savedBundleeverytime the activity comes back from the background. This helps to test android lifecycle issues.

But what else may happen in reality: if the app is in the background for long the android.app.Application object itself will be destroyed/collected while simultaneously keeping the stack information of the activities. Android will then try to recreate the activity with the data from the Intent and savedBundle, but also recreates the android.app.Application object.

So the question: Is there a way to simulate this behaviour?

EDIT: later found this also answered here: How to simulate Android killing my process

Community
  • 1
  • 1
Patrick
  • 33,984
  • 10
  • 106
  • 126
  • "the android.app.Application object itself will be destroyed/collected" -- more accurately, your process will be terminated. – CommonsWare Mar 10 '16 at 15:29

1 Answers1

4

Yes there is:

Just start your app, navigate to the activity you want to test and press the home button (important app needs to be in background). Then either with command line:

adb shell am kill your.app.package.name

or press Terminate Application in Android Studio in the Android Monitor:

Android Studio Screenshot showing Terminate Button

then restart your app with e.g. the launcher icon and the activity will be recreated with a new application object.

Patrick
  • 33,984
  • 10
  • 106
  • 126