我有一個警鈴下面的代碼...問題檢索意圖額外
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(CalendarViewActivity.this, OneShotAlarm.class);
Bundle bun = new Bundle();
bun.putString("data", "hello this is my message...");
intent.putExtras(bun);
PendingIntent sender = PendingIntent.getBroadcast(CalendarViewActivity.this,
0, intent, 0);
// We want the alarm to go off 5 seconds from now. TODO
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 5);
// Schedule the alarm!
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
return false;
}
});
}
public class OneShotAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO
Toast.makeText(context, "Alarm! " + intent.getExtras().getString("data"), Toast.LENGTH_SHORT).show();
}
}
報警正常熄滅,但「數據」額外不獲取檢索出於某種原因,並被設置爲空。
感謝您的幫助!
這解決了這個問題,謝謝 – Jonny