0

I'm in a similar situation to this question: Android Application Class Lifecycle

I'm extending the Application class and using it as a singleton. As I move through my Activities I'm adding and modifying state in my application singleton. I want to test the case where the Android OS shuts down my app to clear memory, and then when you launch the app again the singleton state is gone. Currently, I can only test that by exiting the app and launching a bunch of other ones to try to make this happen, but it takes like 5 minutes.

Is there an easier way to make the Android system flush your running app? Force closing and using the "Don't keep activities" setting on the developer options don't let me test this case.

Community
  • 1
  • 1
Raf
  • 83
  • 1
  • 7

1 Answers1

0

Flush app - is essentially killing an app process. The easiest way to kill a process is:

Process.killProcess(Process.myPid());

Android will restart your process for you though, but as I understand that's what you are looking for

Pavel Dudka
  • 20,754
  • 7
  • 70
  • 83