I am creating a button in my apps and by clicking this button, all the states will be saved and user will exit the whole application. When user re-click on the apps, he/she should be brought to the main activity. I have tried using finish() and System.exit(0) but both of these functions are just ending the current activity and bring me to the previous activity... how can i achieve this? thanks.
Asked
Active
Viewed 2,479 times
1
-
you can resolve this problem by calling startActivtyForResult() other than startActivity() in all parent activities. – Krishna Prasad May 17 '12 at 07:14
-
Have you checked [http://stackoverflow.com/questions/2042222/close-application](http://stackoverflow.com/questions/2042222/close-application) and [http://stackoverflow.com/questions/3226495/android-exit-application-code](http://stackoverflow.com/questions/3226495/android-exit-application-code)? – silwar May 17 '12 at 07:15
-
hope these threads helps you http://stackoverflow.com/questions/3105673/android-how-to-kill-an-application-with-all-its-activities http://stackoverflow.com/questions/6014028/closing-application-with-exit-button – Hassy31 May 17 '12 at 07:22
-
here what is your main activity the very first activity of application or the last activity of application which you quit – Avi Kumar May 17 '12 at 07:41
2 Answers
0
calling Move to Back will hide your application. you shouldn't call System.exit(0);
It's always better to rely on Android OS to decide when a app needs to be killed.

Mayank
- 8,777
- 4
- 35
- 60
0
Find the below code for close the application.Firstly clear the activity stack and using flag then use finish() method.
Intent intent = new Intent(getApplicationContext(), FinishActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(intent);
In FinishActivity class in onCreate() jest simply write finish() method
public class FinishActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
finish();
}
}

Srikanth
- 164
- 2
- 9