0

Possible Duplicate:
Close application and launch home screen on Android

I have developed an application which consist of 23 screens or layout.. Each layout links with another one..

The process will go as a chain or tree.. How can i close my application entirely if i was in the mid of any screen or flow in my application..

If i have single screen means i can use finish() method for closing the application, in this if i use finish() method means it will cross many screens to close my application entirely..

Help me to code for this problem..

Community
  • 1
  • 1
gowri
  • 681
  • 9
  • 27

4 Answers4

1

Try out this way:

android.os.Process.killProcess(android.os.Process.myPid());
Praful Bhatnagar
  • 7,425
  • 2
  • 36
  • 44
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
1

use this code to move your app to background.

Intent homeIntent = new Intent(Intent.ACTION_MAIN);
        homeIntent.addCategory(Intent.CATEGORY_HOME);
        homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(homeIntent);

In other words this will launch the home screen and make your app to move to background.

android.os.Process.killProcess(android.os.Process.myPid()); 

This will stop your app, whereas the above one will make your app to live in the background and resume it from where you left the app of the app was not killed by system already.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
1

You can use android:noHistory="true" in your AndroidManifest.xml in each activity tag.

<activity android:name=".Something" android:noHistory="True" />

Now when u will call next activity via intent. Intent will not store previous activity. so whenever u will click back it will close your app.

karllindmark
  • 6,031
  • 1
  • 26
  • 41
Zohaib
  • 2,845
  • 2
  • 23
  • 33
  • I updated the `android:noHistry=true" to `android:noHistory="true"`. :) – karllindmark Jan 04 '13 at 08:16
  • But if i Need both Back and Exit Button Means? What shall i do?.. Back button for previous Activity and Exit for closing my Application??? – gowri Jan 05 '13 at 05:41
1

call moveTaskToBack(true) on your Activity. This will hide your application until the user wants to use it again.

But it is always preferred not to quit the entire application on a single button's click.

Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100