0
由於某些原因,我在可穿戴設備上創建了通知。由於我也在移動設備上顯示相同的內容,因此我需要同步刪除通知。我發現刪除可穿戴設備和移動設備上的通知需要很長時間。起初我想,這與我正在使用的DataAPI有關,但我錯了。刪除意圖被稱爲一個巨大的延遲,我不知道爲什麼。通過可穿戴設備(〜5秒)執行deleteIntent執行的巨大延遲
這裏查看我的(清潔)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的。延遲也在那裏,但它似乎有點快(但我沒有測量它)。