I got the problem when quit the app from alertDialog. I saw one topic and tested but I couldn't. I also couldn't comment in that topic.
I start the app, intent to many activity. After playing, I back to home of the app and use Back button hard, AlertDialog will appear. But when I press positive, app will return to some activity, app is not quit or force quit.
Below is my code so please check:
@Override
public void onBackPressed() {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setMessage("Do you want to quit the game?");
alertDialog.setCancelable(false);
alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
stopService(new Intent(MainActivity.this, MyService.class));
finish();
}
});
alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
I've already tested with dialog.dismiss and system.exit instead of finish() but it's same.