diff options
author | Andrew Dolgov <[email protected]> | 2018-07-10 15:43:06 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-07-10 15:43:06 +0300 |
commit | c9e43bcbcb88b754643fd75058e2d3420efb3716 (patch) | |
tree | 370bfe2515e821d10e317b585bdad67eb5932d01 /org.fox.ttrss/src/main | |
parent | 8f083deaf7574fb5e043fc849ef633fa619d26cc (diff) |
abort widget service early if there's no widgets to update
Diffstat (limited to 'org.fox.ttrss/src/main')
-rwxr-xr-x | org.fox.ttrss/src/main/java/org/fox/ttrss/widget/WidgetUpdateService.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/widget/WidgetUpdateService.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/widget/WidgetUpdateService.java index ca0b4090..52785998 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/widget/WidgetUpdateService.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/widget/WidgetUpdateService.java @@ -41,6 +41,13 @@ public class WidgetUpdateService extends JobIntentService { Log.d(TAG, "onHandleWork: " + intent); + if (getWidgetCount(getApplicationContext()) == 0) { + Log.d(TAG, "no widgets to work on, bailing out"); + + stopSelf(); + return; + } + try { updateWidgets(-1, UPDATE_IN_PROGRESS); @@ -157,6 +164,13 @@ public class WidgetUpdateService extends JobIntentService { } + private int getWidgetCount(Context context) { + AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); + ComponentName thisAppWidget = new ComponentName(context.getPackageName(), SmallWidgetProvider.class.getName()); + + return appWidgetManager.getAppWidgetIds(thisAppWidget).length; + } + protected boolean isNetworkAvailable() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); |