通知的大量延迟在可穿戴设备上执行deleteIntent执行(~5秒)

时间:2015-02-23 09:03:40

标签: android notifications android-notifications wear-os android-wear-data-api

我出于某些原因在可穿戴设备上创建通知。由于我在移动设备上也显示相同的一个,我需要同步删除通知。我发现删除可穿戴设备和移动设备上的通知需要花费很多时间。起初我想,这与我正在使用的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()

您可能会看到表面变得可见,并且在写入下一个logcat输出之前大约需要5秒钟。

以下是我为删除创建待处理意图的代码:

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的。延迟也存在,但似乎要快一点(但我没有测量它)。

1 个答案:

答案 0 :(得分:0)

在Android磨损中解除通知后,用户有5秒钟撤消操作。如果在解除通知后向下滑动,则应显示撤消按钮。