This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to destroy the application completely?

 
sohaib rahman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Harvinder Thakur
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic