From d9c2442a149d615d764fc3a8cdbd66e24cc2f2a6 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 10 Nov 2016 23:46:40 +0900 Subject: [PATCH] Don't show battery optimization dialog more than once --- .../nutomic/syncthingandroid/activities/MainActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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) -> {