I create notifications on the wearable for some good reasons. Since I display the same one on the mobile too I need to syncronize the deletion of the notifications. I observed that it takes a lot of time between the deletion of the notification on the wearable and the mobile. At first I thought, that this is related to the DataAPI I am using, but I was wrong. The delete intent is called with a huge delay and I don't know why.
Here check my (cleaned) logcat output:
-- Wearable --
09:31:45.007 D/FitnessWatchface﹕ onVisibilityChanged : false
09:31:48.008 D/FitnessWatchface﹕ onVisibilityChanged : true
09:31:52.929 D/NotificationHelper﹕ Got action my.package.name.NOTIFICATION_DISCARDED
09:31:52.963 D/DataAPI﹕ Discard message send out to mobile
09:31:53.052 I/art﹕ WaitForGcToComplete blocked for 10.697ms for cause DisableMovingGc
09:31:53.071 D/DataAPI﹕ Wrote successful wear://1d8...5d7/notification/discard/2
09:31:53.073 D/DataLayerListener﹕ onDataChanged invoked
-- Smartphone --
09:31:53.075 D/DataLayerListener﹕ onMessageReceived: /notification/discard/2
09:31:53.075 D/DataLayerListener﹕ Forwarding DISCARD event to receiver...
09:31:53.075 D/Broadcast﹕ Got DISCARD for type
09:31:53.075 D/NotificationHelper﹕ removeNotification()
09:31:53.165 D/DataLayerListener﹕ onDataChanged: wear://1d8...5d7/notification/discard/2
09:31:53.165 D/DataLayerListener﹕ Forwarding DISCARD event to receiver...
09:31:53.165 D/Broadcast﹕ Got DISCARD for type
09:31:53.165 D/NotificationHelper﹕ removeNotification()
As you may see the watchface becomes visible and it takes about 5 seconds until the next logcat output is written.
Here is the code where I create the pending intent for the deletion:
Intent intent = new Intent(context, NotificationHelper.class);
intent.setAction(NOTIFICATION_DISCARDED);
intent.putExtra(NOTIFICATION_INPUT_TYPE, type);
// prevents that the intent is overridden by the system with similar ones
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
return PendingIntent.getBroadcast(context, 6434, intent, PendingIntent.FLAG_ONE_SHOT);
Do you see something which explains the delay? If you want to see some more code leave a comment.
I just compaied before submitting this question the timings compained to e.g. WhatsApp. The delay is there too, but it seems to be a little faster (but I did not measure it).