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
This commit is contained in:
Hans-Christoph Steiner 2016-05-11 20:25:12 +02:00
parent 62295b72b4
commit 81f13279fe

View File

@ -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
}