I would like to show a notification that shows the progress of the current work. This works well for me. But at the same time, the remote view must contain a cancel button to stop the current operation. The usual intention of the content should still do something else, i.e. Do not cancel the current operation. It seems that I can only have one intention.
I need to specify the contentIntent, which starts when I click on the notification: if I do not indicate that I get something along these lines:
E/ActivityManager( 62): Activity Manager Crash E/ActivityManager( 62): java.lang.IllegalArgumentException: contentIntent required ...
For the Cancel button, I set a different intent:
Intent cancelSyncIntent = new Intent("com.xyz.CANCEL_SYNC"); contentView.setOnClickPendingIntent(R.id.cancel_sync, PendingIntent.getBroadcast(context, 0, cancelSyncIntent, 0));
But it never works. I always get content when the button is clicked. Looks like I canβt use buttons in remote notifications ?!
Perhaps I could display the text: "<<Press to cancel the operation β", but it seems rather heavy.
Update: Afer J recommendations:
final Notification n = new Notification(R.drawable.gen_auto_notification_icon, context.getResources() .getString( fastSyncOnly ? R.string.fast_synchronization_running_notification_title : R.string.synchronization_running_notification_title), new Date().getTime()); n.flags = Notification.FLAG_ONGOING_EVENT; final RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.in_progress_notification); n.contentView = contentView; // Intent cancelSyncIntent = new Intent("com.newsrob.CANCEL_SYNC"); Intent cancelSyncIntent = new Intent(); cancelSyncIntent.setClass(context, FireReceiver.class); PendingIntent pendingCancelSyncIntent = PendingIntent.getActivity(context, 0, cancelSyncIntent, 0); contentView.setOnClickPendingIntent(R.id.cancel_sync, pendingCancelSyncIntent); Intent showDashboardIntent = new Intent(context, DashboardListActivity.class); PendingIntent showDashboardPendingIntent = PendingIntent.getActivity(context, 0, showDashboardIntent, 0); n.contentIntent = showDashboardPendingIntent;