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:
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
posted
0
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?
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?