簡體   English   中英

Android Wear-Extra中的Integer ArrayList為空

[英]Android Wear - Integer ArrayList in Extra comes null

我遇到一個我不知道為什么會發生的問題。

我從手持設備向可穿戴設備發送了通知,以了解何時必須打開活動。

從手持設備,我發送一個整數值的ArrayList:

dataMapRequest.getDataMap().putIntegerArrayList("SELECTED_RISKS", this.selectedRisks);

在WearableListenerService實現中的方法“ onDataChange”中,在我的Wear App中,我通過以下方式獲取值:

ArrayList<Integer> risksSelected = dataMapItem.getDataMap().getIntegerArrayList("SELECTED_RISKS");

這可行。 ArrayList不為null。 然后,將那個ArrayList放在“其他”中,將它們設置為Intent並在Wearable中顯示Notification:

Intent viewIntent = new Intent(this, MainActivity.class);
Bundle extras = new Bundle();
extras.putIntegerArrayList("SELECTED_RISKS", risksSelected);
viewIntent.putExtras(extras);
PendingIntent pendingViewIntent = PendingIntent.getActivity(this, 0, viewIntent, 0);
...

這也有效。 我在調試器中看到Extras正在保存ArrayList。 但是問題來了。

當我嘗試在“ MainActivity”中加載額外內容時:

if(extras.containsKey("SELECTED_RISKS") && extras.getIntegerArrayList("SELECTED_RISKS")!=null)

該捆綁軟件具有鍵“ SELECTED_RISKS”,但其值為空。

我不知道為什么會這樣,您能幫我嗎?

謝謝

這可能是由於PendingIntent是如何工作的。 這是一個常見的問題,當使用PendingIntent時,附加功能會丟失。 如果您之前已經設置了具有特定意圖的PendingIntent ,現在又以唯一的區別是額外設置了它,那么將使用舊的意圖。

看一下PendingIntent的文檔。 具體來說,您可以嘗試使用FLAG_UPDATE_CURRENT強制執行其他功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM