Android Tech

The more we share, the more we get

Category Archives: Android advanced

Kill process of application when exit


When you want to exit an application by press key BACK on menu, you can return the previous screen may be HOME screen or something else (previous screen of running application) but, unfortunately, if you back to HOME screen and think that your application will kill itself automatically, it’s seriously mistake. You have to add process for this action, kill application itself when user press BACK button until out of your app.

To do this, we will use function name “killProcess” as follow:

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

We will insert this code in Destroy event when your application have to go through at exit

    @Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();

try {
commonProcess.DeleteCache(this);
}catch (Exception e) {
Log.e(“GoogleMapDemo”, “Exception”, e);
}

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

If you are using real device, you can check the process with some software like Taskiller example.

Advertisements