Can someone tell me how exit all activity on android studio, because when show alert dialog exit i click exit when progressbar on proses the app close but few second app auto start and show second activity.
Asked
Active
Viewed 88 times
-4
-
1Is this Android or AndroidStudio question? As far as I can tell, Android studio doesn't have "activities". – M. Prokhorov Nov 27 '17 at 16:42
-
Build app using android studio and running on android,, – Dhio Kandhika Nov 28 '17 at 04:52
1 Answers
2
I think you want to exit app when user pressing yes on alert box.. so for this you need to write below code on "yes" button click like this. Source: this answer
@Override
public void onBackPressed() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("Exit Application?");
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}

KhanStan99
- 414
- 8
- 20
-
1
-
Good for you, but these kind of code is easy to find on internet or even on stackoverflow, just search a little bit before asking a question. :) – KhanStan99 Nov 28 '17 at 05:22
-