From 069095e69cd2e94e241ae9cdaaa13be2e3bd0f98 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Mon, 17 Dec 2018 17:17:30 -0300 Subject: [PATCH] Merge pull request #1541 from TeamAmaze/fix-1525 Fix 1525 --- .../filemanager/utils/ServiceWatcherUtil.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/utils/ServiceWatcherUtil.java b/app/src/main/java/com/amaze/filemanager/utils/ServiceWatcherUtil.java index 1cb92c8db4..6eed4bef48 100644 --- a/app/src/main/java/com/amaze/filemanager/utils/ServiceWatcherUtil.java +++ b/app/src/main/java/com/amaze/filemanager/utils/ServiceWatcherUtil.java @@ -96,7 +96,8 @@ public void run() { // we passed at the beginning is never reached // we try to get a less precise size and make our decision based on that progressHandler.addWrittenLength(progressHandler.getTotalSize()); - pendingIntents.remove(); + if (!pendingIntents.isEmpty()) + pendingIntents.remove(); handler.removeCallbacks(this); handlerThread.quit(); return; @@ -127,7 +128,8 @@ public void run() { if (position == progressHandler.getTotalSize() || progressHandler.getCancelled()) { // process complete, free up resources // we've finished the work or process cancelled - pendingIntents.remove(); + if (!pendingIntents.isEmpty()) + pendingIntents.remove(); handler.removeCallbacks(this); handlerThread.quit(); return; @@ -158,15 +160,23 @@ public void stopWatch() { * as there are higher chances for android system to GC the thread when it is running low on memory */ public static synchronized void runService(final Context context, final Intent intent) { - pendingIntents.add(intent); switch (pendingIntents.size()) { + case 0: + context.startService(intent); + break; case 1: // initialize waiting handlers + pendingIntents.add(intent); postWaiting(context); break; case 2: // to avoid notifying repeatedly + pendingIntents.add(intent); notificationManager.notify(NotificationConstants.WAIT_ID, builder.build()); + break; + default: + pendingIntents.add(intent); + break; } }