Closed torian257x closed 11 months ago
Device: OnePlus 9R
Error: Exception in disableAllOptimizations. com.afollestad.materialdialogs.MaterialDialog$DialogException: Bad window token, you cannot show a dialog before an Activity is created or after it's hidden.
Error/Exception on clicking 'disable all optimizations'
old
private void showManBatteryOptimizationDisabler(boolean isRequestNativeBatteryOptimizationDisabler) { BatteryOptimizationUtil.showBatteryOptimizationDialog( mContext, KillerManager.Actions.ACTION_POWERSAVING, manBatteryTitle, manBatteryMessage, () -> { setManBatteryOptimization(true); if (isRequestNativeBatteryOptimizationDisabler) { showIgnoreBatteryPermissions(); } }, () -> { setManBatteryOptimization(false); if (isRequestNativeBatteryOptimizationDisabler) { showIgnoreBatteryPermissions(); } } ); }
causes
BadTokenException or InvalidDisplayException, clean up.
Exception in showDisableManBatteryOptimization. com.afollestad.materialdialogs.MaterialDialog$DialogException: Bad window token, you cannot show a dialog before an Activity is created or after it's hidden.
fix according: https://stackoverflow.com/questions/34481525/bad-window-token-you-cannot-show-a-dialog-before-an-activity-is-created-or-afte
private void showManBatteryOptimizationDisabler(boolean isRequestNativeBatteryOptimizationDisabler) { BatteryOptimizationUtil.showBatteryOptimizationDialog( mActivity, KillerManager.Actions.ACTION_POWERSAVING, manBatteryTitle, manBatteryMessage, () -> { setManBatteryOptimization(true); if (isRequestNativeBatteryOptimizationDisabler) { showIgnoreBatteryPermissions(); } }, () -> { setManBatteryOptimization(false); if (isRequestNativeBatteryOptimizationDisabler) { showIgnoreBatteryPermissions(); } } ); }
notice I assume there are other functions affected by this peculiarity as well e.g. all that call
showBatteryOptimizationDialog
SOMEWHAT WORKING after applying the fix, I get the popup with explanation. What doesn't work if I press on
OK
to change the actual setting. Nothing opens.
@Jossnaz You have a pull request for this or a modified fork?
No I manually patched it in the code of the project (I'm such a bad bad boi I know)
showBatteryOptimizationDialog
is called in 2 places
Just change mContext with mActivity in the 2 places
for me it's just a side project so no point in trying to force PRs on someone who doesn't want them (so it seems)
On Sun, 9 May 2021 at 21:58, Sai Varun Reddy Daram @.***> wrote:
old
private void showManBatteryOptimizationDisabler(boolean isRequestNativeBatteryOptimizationDisabler) { BatteryOptimizationUtil.showBatteryOptimizationDialog( mContext, KillerManager.Actions.ACTION_POWERSAVING, manBatteryTitle, manBatteryMessage, () -> { setManBatteryOptimization(true); if (isRequestNativeBatteryOptimizationDisabler) { showIgnoreBatteryPermissions(); } }, () -> { setManBatteryOptimization(false); if (isRequestNativeBatteryOptimizationDisabler) { showIgnoreBatteryPermissions(); } } ); }
causes
BadTokenException or InvalidDisplayException, clean up.
Exception in showDisableManBatteryOptimization. com.afollestad.materialdialogs.MaterialDialog$DialogException: Bad window token, you cannot show a dialog before an Activity is created or after it's hidden.
fix according:
private void showManBatteryOptimizationDisabler(boolean isRequestNativeBatteryOptimizationDisabler) { BatteryOptimizationUtil.showBatteryOptimizationDialog( mActivity, KillerManager.Actions.ACTION_POWERSAVING, manBatteryTitle, manBatteryMessage, () -> { setManBatteryOptimization(true); if (isRequestNativeBatteryOptimizationDisabler) { showIgnoreBatteryPermissions(); } }, () -> { setManBatteryOptimization(false); if (isRequestNativeBatteryOptimizationDisabler) { showIgnoreBatteryPermissions(); } } ); }
notice I assume there are other functions affected by this peculiarity as well e.g. all that call showBatteryOptimizationDialog
SOMEWHAT WORKING after applying the fix, I get the popup with explanation. What doesn't work if I press on OK to change the actual setting. Nothing opens.
@Jossnaz https://github.com/Jossnaz You have a pull request for this or a modified fork?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pvsvamsi/Disable-Battery-Optimizations/issues/2#issuecomment-836098369, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPZ36UPFJXPQX4TOSRKKVDTM5DT3ANCNFSM434EQCKA .
This is fixed in latest versions
old
causes
fix according: https://stackoverflow.com/questions/34481525/bad-window-token-you-cannot-show-a-dialog-before-an-activity-is-created-or-afte
notice I assume there are other functions affected by this peculiarity as well e.g. all that call
showBatteryOptimizationDialog
SOMEWHAT WORKING after applying the fix, I get the popup with explanation. What doesn't work if I press on
OK
to change the actual setting. Nothing opens.