Skip to content

Commit

Permalink
Merge pull request #6504 from evermind-zz/fixes-choice-dialog
Browse files Browse the repository at this point in the history
dismiss choice dialog in onStop() to avoid a leaked window Exception:
  • Loading branch information
Redirion authored Jun 17, 2021
2 parents 841fb4c + a9ab2f5 commit 0803d9f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class RouterActivity extends AppCompatActivity {
protected String currentUrl;
private StreamingService currentService;
private boolean selectionIsDownload = false;
private AlertDialog alertDialogChoice = null;

@Override
protected void onCreate(final Bundle savedInstanceState) {
Expand All @@ -126,6 +127,15 @@ protected void onCreate(final Bundle savedInstanceState) {
? R.style.RouterActivityThemeLight : R.style.RouterActivityThemeDark);
}

@Override
protected void onStop() {
super.onStop();
// we need to dismiss the dialog before leaving the activity or we get leaks
if (alertDialogChoice != null) {
alertDialogChoice.dismiss();
}
}

@Override
protected void onSaveInstanceState(@NonNull final Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down Expand Up @@ -333,7 +343,7 @@ private void showDialog(final List<AdapterChoiceItem> choices) {
}
};

final AlertDialog alertDialog = new AlertDialog.Builder(themeWrapperContext)
alertDialogChoice = new AlertDialog.Builder(themeWrapperContext)
.setTitle(R.string.preferred_open_action_share_menu_title)
.setView(radioGroup)
.setCancelable(true)
Expand All @@ -347,12 +357,12 @@ private void showDialog(final List<AdapterChoiceItem> choices) {
.create();

//noinspection CodeBlock2Expr
alertDialog.setOnShowListener(dialog -> {
setDialogButtonsState(alertDialog, radioGroup.getCheckedRadioButtonId() != -1);
alertDialogChoice.setOnShowListener(dialog -> {
setDialogButtonsState(alertDialogChoice, radioGroup.getCheckedRadioButtonId() != -1);
});

radioGroup.setOnCheckedChangeListener((group, checkedId) ->
setDialogButtonsState(alertDialog, true));
setDialogButtonsState(alertDialogChoice, true));
final View.OnClickListener radioButtonsClickListener = v -> {
final int indexOfChild = radioGroup.indexOfChild(v);
if (indexOfChild == -1) {
Expand Down Expand Up @@ -402,10 +412,10 @@ private void showDialog(final List<AdapterChoiceItem> choices) {
}
selectedPreviously = selectedRadioPosition;

alertDialog.show();
alertDialogChoice.show();

if (DeviceUtils.isTv(this)) {
FocusOverlayView.setupFocusObserver(alertDialog);
FocusOverlayView.setupFocusObserver(alertDialogChoice);
}
}

Expand Down

0 comments on commit 0803d9f

Please sign in to comment.