views:

317

answers:

2

So I have my Activity, and on pressing a "Quit" button I call Activity.finish(). This effectively closes my application.

The problem: The Dalvik-process of my application is still hanging around as a zombie in background. It seems like this is normal as other applications do the same. Even The hello-world example hangs around in memory..

I could live with this, but unfortunatley this behaviour makes the development of my application a pain. I have a remote service connected to my Activity, and this service won't unload until my Activity unloads (which as said it never does).

Everything is somehow kept alive for no good reason.

How can I really remove my Activity from memory?

I'm looking for something like Activity.finish_and_kill_my_process_please() call or something similar.

+2  A: 

Try using the killBackgroundProcesses method:

ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses("name.of.your.package");

You will need to add the KILL_BACKGROUND_PROCESSES permission to your AndroidManifest.xml file.

Cristian
+5  A: 

So I have my Activity, and on pressing a "Quit" button I call Activity.finish(). This effectively closes my application.

Please don't do this.

The Dalvik-process of my application is still hanging around as a zombie in background.

The process is kept in a cache, for potential reuse by Android. You can safely ignore it.

I have a remote service connected to my Activity, and this service won't unload until my Activity unloads (which as said it never does).

You probably have a bug in your application, such as calling startService() and failing to call stopService(), or calling bindService() and failing to call unbindService().

CommonsWare