diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java index 71f881a5..66459271 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java @@ -67,6 +67,7 @@ public class MainActivity extends SyncthingActivity private static final long USAGE_REPORTING_DIALOG_DELAY = TimeUnit.DAYS.toMillis(3); private AlertDialog mDisabledDialog; + private AlertDialog mBatteryOptimizationsDialog; private ViewPager mViewPager; @@ -112,12 +113,13 @@ public class MainActivity extends SyncthingActivity SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); boolean dontShowAgain = sp.getBoolean("battery_optimization_dont_show_again", false); - if (dontShowAgain || Build.VERSION.SDK_INT < Build.VERSION_CODES.M || + if (dontShowAgain || mBatteryOptimizationsDialog != null || + Build.VERSION.SDK_INT < Build.VERSION_CODES.M || pm.isIgnoringBatteryOptimizations(getPackageName())) { return; } - new AlertDialog.Builder(this) + mBatteryOptimizationsDialog = new AlertDialog.Builder(this) .setTitle(R.string.dialog_disable_battery_optimization_title) .setMessage(R.string.dialog_disable_battery_optimization_message) .setPositiveButton(R.string.dialog_disable_battery_optimization_turn_off, (d, i) -> {