Skip to content

Commit

Permalink
Merge pull request #1541 from TeamAmaze/fix-1525
Browse files Browse the repository at this point in the history
Fix 1525
  • Loading branch information
EmmanuelMess committed Dec 17, 2018
1 parent 6488833 commit 069095e
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 069095e

Please sign in to comment.