2012-01-21 48 views
3

我打算做一個簡單的鬧鐘,我有用戶界面,我正在使用Bundle發送報警的用戶配置(如音量值或音調類型)。 在主要活動中,我有:如何在Android中更新我在服務中的Bundle數據?

Bundle b = new Bundle(); 
b.putString("tone", toneS.getSelectedItem().toString()); 

而且我把它發送到廣播接收器:

Intent intent = new Intent(SetAlarm.this, MessageReceiver.class); 
      intent.putExtras(setBoundle()); 

我收到包在廣播接收器以這樣的方式

Bundle b2 = new Bundle(); 
     b2 = intent.getExtras(); 

它完全適用於第一次,但在它之後,儘管主要活動中的Bundle有來自UI的新數據,但BroadcastReceiver只保留舊數據。

任何人都可以解釋這個問題嗎?

回答

2

每當我這樣做,我發送一個新的Bundle,並把字符串放在那。
發送端的意圖可以重複使用,只要你喜歡

希望這有助於!

3

我正面臨類似的問題,大量的淨研究後,我知道了,這個問題的解決辦法是隱藏在我們如何instance.Firstly PandingIntent我創造這樣的PI實例: -

pendingIntent = PendingIntent.getService(SettingsScreen.this, 0, myIntent, 0); 

但如果你想更新你得把PendingIntent.FLAG_CANCEL_CURRENTFLAG_UPDATE_CURRENT去年parameter.so的PendingIndent實例的PendingIntent的實例,所以捆數據將是: -

pendingIntent = PendingIntent.getService(SettingsScreen.this, 0, myIntent, 
PendingIntent.FLAG_CANCEL_CURRENT); 

pendingIntent = PendingIntent.getService(SettingsScreen.this, 0, myIntent, 
PendingIntent.FLAG_UPDATE_CURRENT); 

這解決了我的問題,我希望它也能解決你的問題。

相關問題