The moose likes Android and the fly likes How to destroy the application completely? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Mobile » Android
Reply Bookmark "How to destroy the application completely?" Watch "How to destroy the application completely?" New topic
Author

How to destroy the application completely?

sohaib rahman
Greenhorn

Joined: Jun 01, 2010
Posts: 20
Dear folks,

We all know that when we call the finish() method of the activity on click of a button, say "Exit", the application exits. True. This is true for my app which I am creating. All the activity's current state are destroyed.
I have written the following code:

btnExit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

finish();

}

}

But the problem is that, if the user clicks on the home button directly without clicking on the "Exit" button, the application state remains as it is. The point from where I exit the application on the press of the home button of the android phone, remains as it is as if it is asking me to continue from where I have left. How to destroy the application completely? Please do not ask me to search this forum. I've already done that.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 32769
What are you trying to achieve by exiting the app completely that you couldn't achieve by implementing the onPause/onStop/onDestroy methods of the main activity?


Android appsImageJ pluginsJava web charts
Harvinder Thakur
Ranch Hand

Joined: Jun 10, 2008
Posts: 231
Hi Shoaib,

Why would you want to ensure that the application exits?

If a user does not exit the application and goes to the Home app. then we can assume that s/he is deliberately navigating away from your activity, thus making the process in which the activity is running into a "background process" I guess.

As per the Android Process lifecycle the OS would sooner or later kill the process depending upon the memory requirements.

So, if you really want to exit the app for some reason then maybe you could custom implement the onPause(), onStop() methods. e.g. if activity remains onPause() or onStop() for a specified duration of time then call onDestroy(). But then you need to be really sure that the user actually wants to exit your app and does not want to return to it at some later point in time and that's a bit difficult to guess.


thanks
Harvinder
 
 
subject: How to destroy the application completely?
 
Threads others viewed
Listen to Caps Lock Key event
How to Exit an Application
buttons, mnemonics, dialogs and frames
Exiting from Applet
Exiting from application
developer file tools