Application to kill own process when exited

Put your problem here if it does not fit any of the other categories.

Application to kill own process when exited

Postby rackham » Mon Jan 04, 2010 2:18 pm

Hello all. Ive been reading about the general behaviour of android apps when a user uses the back button to return to the desktop (or whatever it may be called on a phone!).

Using the emulator i have noticed that while when using the back button each individual activitys onDestory() method is call, but when all activitys from a task have been removed, it's process still remains (unless i kill it using ddms)

Reading differnt forums it seems that everyone says its up to the developer to kill an app properly but i dont see any info on how to do this and or what nessercary, shall i just leave the process alone? Seems like a waste when there is no reason for it to be there.

One post said to look here AcitictyManager but it dosent really answer my questions above. Any help would be greatly appreciated!

Thanks,

Dori
rackham
Junior Developer
Junior Developer
 
Posts: 15
Joined: Tue Oct 06, 2009 10:47 am

Top

Postby rackham » Mon Jan 04, 2010 3:54 pm

For anyone who comes across this and thinks i wish the answer was posted, here it is!

put this code in an activity say...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ActivityManager aM = (ActivityManager) getApplicationContext().getSystemService( ACTIVITY_SERVICE );
  2.  
  3. aM.restartPackage(getApplicationContext().getPackageName());
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


and this in your manifest

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission android:name="android.permission.RESTART_PACKAGES" />
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


contrary to the method name, this closes the package (and process) that the method is called from, as opposed to restarting it.
rackham
Junior Developer
Junior Developer
 
Posts: 15
Joined: Tue Oct 06, 2009 10:47 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests