0

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • 1
    Possible duplicate of [How to force stop an Android app](https://stackoverflow.com/questions/29887429/how-to-force-stop-an-android-app) – Adinia Jan 18 '19 at 11:47
  • Yes, but I couldn't comment in that. Also, I want quit from alertDialog, so how can I do? –  Jan 18 '19 at 12:08
  • have you tried finishAndRemoveTask() ? – Stef Jan 18 '19 at 12:14
  • Yes, I also tried finishAndRemoveTask() but it's same problem –  Jan 18 '19 at 12:23
  • ActivityC back to ActivityB and back to ActivityHome and press Back hard button to show dialog and press Yes, It will jump to ActivityB. –  Jan 18 '19 at 12:45
  • have you tried finishAffinity()? – JideGuru Jan 18 '19 at 14:52
  • I've already tested all from everyone. finish, finishAndRomoveTask, ... even I'm don't know exactly those function because I'm studying. –  Jan 18 '19 at 16:19

1 Answers1

0

After checking, I changed one thing for all activity and it's working now.

In manifests, I change the tag <activity android:.../> instead of <activity android:...></activity>

Only difference </activity> I don't know why.