我有一個非常奇怪的問題。 我知道如何使用PutExtra/getExtras將數據從意圖傳遞到另一個意圖。 當我想要獲得在兩個intents之間傳遞的數據時,它會得到NullPointerException。 我試圖通過傳遞一個包來實現,發生同樣的問題。 所以我試圖把它傳遞給另一個活動,它通過了! 爲什麼第一個活動無法檢索通過的數據?!無法從特定活動中獲取額外信息
0
A
回答
0
例子:
ActivityA:
Intent i = new Intent(this, ActivityB.class);
i.putExtra("identifier", "some text");
startActivity(i);
ActivityB:
Intent intent = getIntent();
String string = intent.getStringExtra("identifier"); //String because your extra is a String value
你有沒有做過這樣的嗎?
0
這就是我所做的。
從IntentServiceClass:
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(context, class1);
intent.putExtra("test", "test");
PendingIntent pendingIntent = PendingIntent.getActivity (context, 0, intent, 0);
從活動課:
String test = getIntent().getExtras().getString("test");
它會導致空指針異常
試驗多次後,我創建了一個新的活動和複製/粘貼相同的代碼,它的工作! 所以我問,爲什麼它沒有與第一類工作?
相關問題
- 1. 如何從json獲取額外信息?
- 2. Perl - 從URL中獲取特定信息
- 3. 獲取額外的PaperSource詳細信息
- 4. 從JDO中的關係表中獲取額外信息
- 5. SharePoint:無法從外部列表中獲取信息
- 6. 將活動中額外的意圖信息傳遞到視圖
- 7. 從兒童活動中獲取額外收益
- 8. ICS Eclipse - 無法從PHP獲取信息
- 9. 從WinAPI文件更改通知獲取額外信息
- 10. 無法啓動活動組件信息
- 11. 提取額外的方法信息,從DLL的
- 12. 從文本中提取特定信息
- 13. 無法獲得額外的一個活動
- 14. 從活動Kotlin獲取字符串額外
- 15. 如何從Google日曆活動中獲取電視信息?
- 16. 無法從特定機器獲取項目信息和源代碼控制
- 17. 無法從意圖獲得額外
- 18. 數據綁定+添加額外信息
- 19. 無法從RSS中提取信息 - Xcode
- 20. 嘗試獲取特定外鍵的信息
- 21. 從特定字符串獲取金額
- 22. jqGrid訪問額外信息
- 23. 有額外的信息
- 24. jQuery.ui autocomplete - 額外信息
- 25. 從activityInventIntent中獲取額外的信息launchMode =「singleTop」與多個通知
- 26. 從解析器數據中獲取特定索引的信息
- 27. 如何從XML中獲取特定信息(Python)
- 28. Geotools獲取特徵信息
- 29. 從特定字符串提取信息
- 30. 無法從使用Firebase的通知中啓動特定活動
你能發表一些代碼嗎?這有很多可能的原因 – Jim
使用Intent/Bundle從這兩個活動中發送/獲取數據的相關部分顯示 –
您能否提供一些代碼? – MrWasdennnoch