【发布时间】:2015-02-23 09:03:40
【问题描述】:
出于某些充分的原因,我在可穿戴设备上创建通知。由于我在移动设备上也显示了相同的内容,因此我需要同步删除通知。我观察到删除可穿戴设备和移动设备上的通知之间需要很长时间。起初我以为这与我使用的 DataAPI 有关,但我错了。删除意图的调用延迟很大,我不知道为什么。
在这里检查我的(清理过的)logcat 输出:
-- 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()
您可能会看到表盘变得可见,并且大约需要 5 秒才能写入下一个 logcat 输出。
这是我创建待删除意图的代码:
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);
您是否看到解释延迟的原因?如果您想查看更多代码,请发表评论。
我只是在提交这个问题之前比较了时间安排,例如WhatsApp。延迟也是有的,不过好像快了一点(不过我没量过)。
【问题讨论】:
标签: android notifications android-notifications wear-os android-wear-data-api