dismiss choice dialog in onStop() to avoid a leaked window Exception:
E/WindowManager: android.view.WindowLeaked: Activity org.schabi.newpipe.RouterActivity has leaked window DecorView@d99fe3b[] that was originally added here at android.view.ViewRootImpl.<init>(ViewRootImpl.java:418)
This commit is contained in:
parent
d6e0bd8c26
commit
a9ab2f54ea
|
@ -107,6 +107,7 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
protected String currentUrl;
|
protected String currentUrl;
|
||||||
private StreamingService currentService;
|
private StreamingService currentService;
|
||||||
private boolean selectionIsDownload = false;
|
private boolean selectionIsDownload = false;
|
||||||
|
private AlertDialog alertDialogChoice = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
|
@ -126,6 +127,15 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
? R.style.RouterActivityThemeLight : R.style.RouterActivityThemeDark);
|
? 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
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull final Bundle outState) {
|
protected void onSaveInstanceState(@NonNull final Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
@ -333,7 +343,7 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final AlertDialog alertDialog = new AlertDialog.Builder(themeWrapperContext)
|
alertDialogChoice = new AlertDialog.Builder(themeWrapperContext)
|
||||||
.setTitle(R.string.preferred_open_action_share_menu_title)
|
.setTitle(R.string.preferred_open_action_share_menu_title)
|
||||||
.setView(radioGroup)
|
.setView(radioGroup)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
|
@ -347,12 +357,12 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
//noinspection CodeBlock2Expr
|
//noinspection CodeBlock2Expr
|
||||||
alertDialog.setOnShowListener(dialog -> {
|
alertDialogChoice.setOnShowListener(dialog -> {
|
||||||
setDialogButtonsState(alertDialog, radioGroup.getCheckedRadioButtonId() != -1);
|
setDialogButtonsState(alertDialogChoice, radioGroup.getCheckedRadioButtonId() != -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
radioGroup.setOnCheckedChangeListener((group, checkedId) ->
|
radioGroup.setOnCheckedChangeListener((group, checkedId) ->
|
||||||
setDialogButtonsState(alertDialog, true));
|
setDialogButtonsState(alertDialogChoice, true));
|
||||||
final View.OnClickListener radioButtonsClickListener = v -> {
|
final View.OnClickListener radioButtonsClickListener = v -> {
|
||||||
final int indexOfChild = radioGroup.indexOfChild(v);
|
final int indexOfChild = radioGroup.indexOfChild(v);
|
||||||
if (indexOfChild == -1) {
|
if (indexOfChild == -1) {
|
||||||
|
@ -402,10 +412,10 @@ public class RouterActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
selectedPreviously = selectedRadioPosition;
|
selectedPreviously = selectedRadioPosition;
|
||||||
|
|
||||||
alertDialog.show();
|
alertDialogChoice.show();
|
||||||
|
|
||||||
if (DeviceUtils.isTv(this)) {
|
if (DeviceUtils.isTv(this)) {
|
||||||
FocusOverlayView.setupFocusObserver(alertDialog);
|
FocusOverlayView.setupFocusObserver(alertDialogChoice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue