我試圖通過傳遞從一類「玩」的延伸活動的字符串:如何在不擴展Activity的類中使用getIntent()?
Bundle data = new Bundle();
Intent i = new Intent(Play.this, Receive.class);
String category;
data.putString("key", category);
i.putExtras(data);
於是,「接收」類,這是一種非活性類,並不延伸活動將接受字符串從「播放」。
但是,當我嘗試接收使用此代碼數據:
Bundle receive = new Bundle();
String passed;
receive = getIntent().getExtras();
passed = receive.getString("key");
我得到了字「getIntent()」的錯誤,並建議我創造的方法getIntent()。
這個問題的可能解決方案是什麼? 感謝!
意圖用於活動之間的溝通。沒有辦法通過意向將信息發送給一個簡單的類。您應該使用通信的其他方式將信息發送到一個「非活動」類 – Sprigg 2013-02-18 13:27:48
你可以檢查我的答案貼出如果這是你的唯一案例。 – Prateek 2013-02-18 13:37:09