2012-01-13 4 views
0

余分なインテントから値を削除するにはどうすればよいですか?BroadcastReceiverのインテントが正しく動作しない

活動:

@Override 
public void onCreate(Bundle savedInstanceState) { 

... 

Intent intent = new Intent(this, MyBroadcastReceiver .class); 
intent.putExtra("valueOne", "valOne"); 
intent.putExtra("valueTwo", true); 
intent.putExtra("valueThree", 1); 

PendingIntent pendingIntent = PendingIntent.getBroadcast(
    this.getApplicationContext(), 234324243, intent, 0); 

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() 
    + (5 * 1000), pendingIntent); 

... 

} 

BroadcastReceiver:

@Override 
public void onReceive(Context context, Intent intent) { 

... 

String valueOne= intent.getStringExtra("valueOne"); 
Boolean valueTwo= intent.getBooleanExtra("valueTwo", false); 
Integer valueThree= intent.getIntExtra("valueThree", 0); 

// Log.i("info", valueOne) >> valOne 
// Log.i("info", valueTwo.toString()) >> false 
// Log.i("info", valueThree.toString()) >> 1 

...

}

私は活動の値を変更し、再度アプリケーションを実行すると、私は以下のように同じ値を取得最初のスタートで。私は自分の携帯電話/仮想マシン、クリーンプロジェクトが、問題の滞在からアプリを削除してみてください:(

誰が私を助けて

答えて

4

保留中のテントの宣言では、以下のフラグを設定してみてください:?

PendingIntent.FLAG_UPDATE_CURRENT 

。私はここの人々があなたの問題のコードを読むために喜んされるように、あなたがここにあなたのコードをフォーマットすることをお勧め、

PendingIntent pendingIntent = PendingIntent.getBroadcast(
    this.getApplicationContext(), 234324243, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
2

まずあなたのコードリストの上:あなたのケースでは、次のようにする必要があります。 BroadcastReceiverをシステムに登録しません。詳細については、ApiDemoをチェックする方がいいでしょう。

this one

関連する問題