From 81f13279fe3818966e018fada0343c13d8b2144f Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 11 May 2016 20:25:12 +0200 Subject: [PATCH] some tricks to get Cancel working on the download Notification I wrestled with this a bunch, it seems quite difficult to make the Cancel button on the notification responsive. This collection of minor changes made it more reliable, but its still kind of flaky. I think the problem might be related to the fact that it is creating a whole new Notification instance, with the accompanying Intent and PendingIntent instances, for every single download progress update. closes #652 https://gitlab.com/fdroid/fdroidclient/issues/652 --- .../main/java/org/fdroid/fdroid/net/DownloaderService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java index b43a5ff53..7e5961d95 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java @@ -142,17 +142,18 @@ public class DownloaderService extends Service { public static PendingIntent getCancelPendingIntent(Context context, String urlString) { Intent cancelIntent = new Intent(context.getApplicationContext(), DownloaderService.class) .setData(Uri.parse(urlString)) - .setAction(ACTION_CANCEL); + .setAction(ACTION_CANCEL) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); return PendingIntent.getService(context.getApplicationContext(), urlString.hashCode(), cancelIntent, - PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent.FLAG_UPDATE_CURRENT); } @Override public int onStartCommand(Intent intent, int flags, int startId) { - onStart(intent, startId); Utils.debugLog(TAG, "onStartCommand " + intent); + onStart(intent, startId); return START_REDELIVER_INTENT; // if killed before completion, retry Intent }