1

following are the ways to exits from the application

 1. ActivityObject.finish();
 2. Runtime.getRuntime().exit(0);

I want to know which way is to be used & when ?
if there is another way please let me know

Thanks in advance. Shrenik

Shrenik
  • 399
  • 2
  • 5
  • 22
  • 1
    ActivityObject.finish() isn't suitable? – Olegas Mar 28 '11 at 08:22
  • Also, what is "exit from application"? You need to close the current running activity, or you are trying to forcle close your application? – Olegas Mar 28 '11 at 08:30
  • 1
    possible duplicate of [Quitting an application - is that frowned upon?](http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon) – Konstantin Burov Mar 28 '11 at 08:55

3 Answers3

3

That's usually not a good idea at all to "exit" an application in android. That's against Android nature. Read this topic first before doing something like that.

Community
  • 1
  • 1
Konstantin Burov
  • 68,980
  • 16
  • 115
  • 93
  • I understand and have read arguments for not doing this many times but it is immediately obvious to me that the application management in android sucks. There are various task killers to help boost (noticeably) performance. Why shouldn't an app exit if it is no longer needed? – Colton May 07 '13 at 18:19
1

Look at this life cycle of an Android activity: enter image description here

And the description of the OnDestroy state:

The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.

So calling ActivityObject.finish() is the right way to do it.

Community
  • 1
  • 1
  • but Activity.finish() just suggests that the activity can be finish it does not guarantee it will be terminated by the system. System.exit will do that - but it is not recommended – gheese Sep 13 '12 at 07:02
0

call moveTaskToBack(true) on your Activity

surfealokesea
  • 4,971
  • 4
  • 28
  • 38