3

Possible Duplicate:
Android: How to kill an application with all its activities?

I am looking for a way to kill an entire application (e.g. shut down the process) in case my app crashes. The reason I want to do this is because a lot of my runtime data is stored in a static class, and so when the app crashes, this class is killed.

I have seen related questions about the Android philosophy (e.g. about not killing an app etc.), but for now I just need to kill my application. How can I do this?

My app has multiple activities and I tried the following. All it does is restore the previous activity.

System.exit(0)


 ActivityManager servMng
 servMng = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
 servMng.killBackgroundProcesses(<my package name>);


android.os.Process.sendSignal(android.os.Process.myPid(),
android.os.Process.SIGNAL_KILL);

android.os.Process.killProcess(android.os.Process.myPid());

Community
  • 1
  • 1
user510164
  • 626
  • 1
  • 8
  • 17

2 Answers2

8
android.os.Process.killProcess(android.os.Process.myPid());

Credit to @Thirumal Also possible duplicate How to kill an application with all its activities?

Community
  • 1
  • 1
YankeeWhiskey
  • 1,522
  • 4
  • 20
  • 32
  • I also tried this, but it also kills only the current activity and restores the previous activity. Sorry, I forgot to mention it earlier. I will edit my question. – user510164 Sep 08 '12 at 05:35
0

AFAIK android philosophy doesnt allow one to kill an entire app from memory.Android could decide to keep you app in memory for faster subsequent accesses or it could decide to flush it. You have to deal with the individual components like activities, Services. Close each one of them at proper times and you shouldn't have any issues. Make you static variables null when you dont need them..

Akhil
  • 13,888
  • 7
  • 35
  • 39