From 73f30f5686a373ae7f62a94298ab5f1712c97f51 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Tue, 1 Oct 2019 17:19:18 +0300 Subject: [PATCH] Fix for AlertDialog window leak error --- .../gr/thmmy/mthmmy/activities/topic/TopicActivity.java | 9 +++++++-- app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index e0e52b3e..2bb084e3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -123,6 +123,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo private Snackbar snackbar; private TopicViewModel viewModel; private EmojiKeyboard emojiKeyboard; + private AlertDialog topicInfoDialog; //Fix for vector drawables on android <21 static { @@ -253,8 +254,8 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo usersViewing.setText(HTMLUtils.getSpannableFromHtml(this, topicViewers)); }); builder.setView(infoDialog); - AlertDialog dialog = builder.create(); - dialog.show(); + topicInfoDialog = builder.create(); + topicInfoDialog.show(); return true; case R.id.menu_share: Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); @@ -312,6 +313,10 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo @Override protected void onDestroy() { super.onDestroy(); + if(topicInfoDialog!=null){ + topicInfoDialog.dismiss(); + topicInfoDialog=null; + } recyclerView.setAdapter(null); viewModel.stopLoading(); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index c7c7360d..22357d76 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -548,7 +548,7 @@ public abstract class BaseActivity extends AppCompatActivity { AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle); builder.setTitle("Logout"); builder.setMessage("Are you sure that you want to logout?"); - builder.setPositiveButton("Yes", (dialogInterface, i) -> { + builder.setPositiveButton("Yep", (dialogInterface, i) -> { new LogoutTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); //Avoid delays between onPreExecute() and doInBackground() }); builder.setNegativeButton("Nope", (dialogInterface, i) -> {});