1

I am using this link 1 to detect the swiping right on my main activity and using this link 2 to put the alertbuilder in the event Handler.

Link 1: Android: How to handle right to left swipe gestures

Link2: How can I put "Are you sure you want to exit?" when I press back button android

But I get an error

E/WindowManager: android.view.WindowLeaked: Activity de.dfki.av.mhs.peripheralwatch.MainActivity has leaked window DecorView@334a170[MainActivity] that was originally added here

How to add a confirmation screen for the user before he exits the app?

Zain
  • 37,492
  • 7
  • 60
  • 84

1 Answers1

0

if you followed that steps then you have implemented the onbackpressed of activity but be aware dont call super.onbackpressed before the dialog.show().

Also be sure to call finish() on button click of dialog instead of onbackpress.

Error is saying that you are showing dialog after exiting the activity.

@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
       .setMessage("Are you sure you want to exit?")
       .setCancelable(false)
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                ExampleActivity.this.finish();
           }
       })
       .setNegativeButton("No", null)
       .show();

}

Waqas Yousaf
  • 264
  • 4
  • 13