• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

How to destroy the application completely?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43076
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic