harish
harish

Reputation: 255

How to exit an application completely in ANDROID

I have an application.In that if we press on home button app closes but when i launch the app it resumes where i stopped.I mean it do not closed completely.how to solve this problem.

Upvotes: 2

Views: 5464

Answers (4)

brig
brig

Reputation: 3773

You need to call finish() in your onDestroy() method.

Upvotes: 0

the100rabh
the100rabh

Reputation: 4147

Android does not allow you to terminate the application at any time. Application lifecycle is maintained by the Android OS itself. You are not supposed to meddle with it. Unlike desktop applications, Android application lifetime is determined by the OS itself. You can only end an activity.

For more Info refer to this bug http://code.google.com/p/android/issues/detail?id=1572

Upvotes: 1

When you press Home button, onDestroy method of the current activity is called. You can perform any shutdown operations there. Design of Android doesn't have a concept of explicit application shutdown, so that the user can continue on the same activity where he started.

You are trying to copy desktop application behavior (the application is shutdown explicitly) to Android with different usage patterns. While this is understandable, in most cases this will contradict to other applications behavior and will annoy users. So if you have anything to shutdown, do this in onDestroy method.

Upvotes: 4

Drew
Drew

Reputation: 2299

You can make your android app return to the root activity each time you open it by modifying your AndroidManifest.xml to include

android:clearTaskOnLaunch="true"

in the desired <activity> declaration.

Upvotes: 3

Related Questions