0

I have 5 activities. When I click on any button in any of those 5 activities, I want to close the application and when I reopen it, I want to launch the application from first activity. Can any one help me.

I used this code :

    CurrentActivity.this.moveTaskToBack(true);
    android.os.Process.killProcess(android.os.Process.myPid());

It's working fine, but when i relaunch the app it does not shows the first activity.

Purush Pawar
  • 4,263
  • 2
  • 29
  • 37
User
  • 1,251
  • 1
  • 14
  • 19
  • 2
    Why do you want to do this? Why not let your app navigate like Android apps are supposed to and like 99% of them do? A "Close" button in an app is an ugly thing. – Simon Jan 31 '13 at 13:45
  • possible duplicate of [Close Android Application](http://stackoverflow.com/questions/3279578/close-android-application) – John Boker Jan 31 '13 at 13:45
  • @Simon i agree, the huntington bank app has this button and you cant get out of the app without tapping it, not even the back button works to get out of the app. terrible design. – John Boker Jan 31 '13 at 13:46
  • This is not a good practice. So please! Let Android System do that for you. –  Jan 31 '13 at 13:46
  • @SImon, I have requirement for every activity i have exit button, when i click on exit button close the app – User Jan 31 '13 at 13:49
  • 1
    Your "requirement" is utter garbage. http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238#2034238 – CommonsWare Jan 31 '13 at 14:08

3 Answers3

0

Use finish() to pop your Activity from backstack but always be aware of BackStack , you can clear your back stack with this flag : FLAG_ACTIVITY_CLEAR_TOP and Use this flag when you are starting your Activity so when you are starting your 5th Activity there is just your 5th Activity in stack and finishing it cause your App to close.

Arash GM
  • 10,316
  • 6
  • 58
  • 76
0

what you are doing is not proper way as you are killing the process which kills every activity inside the process.This makes your application unstable whenever you opened it again.What you are using currently is used in android task manager which is only authorized way to kill application. I suggest you to use finish().

kaushal trivedi
  • 3,405
  • 3
  • 29
  • 47
0

This is the best way I have found. It kills all the activities of an app and returns the user to the home screen.

//Takes user to home screen
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
//Kills all activities of app
System.exit(0);
Paul
  • 1
  • 2