for3st for3st - 1 month ago 13
Android Question

Is there a way in Android to simulate a destroyed/collected android.app.Application (Object) like "don't keep activities" does for Activities?

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
savedBundle
everytime 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

Answer

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.

Comments