Android Tech

The more we share, the more we get

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

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: