3
我正在使用鬧鐘應用程序。我遵循Android AlarmController教程,只做了一些小改動。出於某種原因,我的廣播接收器的onReceive()方法在鬧鐘響起時沒有被調用。這裏的代碼:基本Android報警應用程序,廣播接收器的onReceive()方法不被調用
// the callback received when the user "sets" the time in the dialog
private TimePickerDialog.OnTimeSetListener mTimeSetListener =
new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
time.set(Calendar.HOUR_OF_DAY, hourOfDay);
time.set(Calendar.MINUTE, minute);
// Tell user alarm was set
String timeSetTo = "Alarm Set: " + time.get(Calendar.HOUR_OF_DAY) + ":" + time.get(Calendar.MINUTE) + " " + time.get(Calendar.AM_PM);
if(toast != null)
toast.cancel();
toast = Toast.makeText(AlarmUI.this, "L" + timeSetTo, Toast.LENGTH_LONG);
toast.show();
// When the alarm goes off we want to send an Intent to our Broadcast Receiver (AlarmAction),
// so set an Intent between the AlarmUI and the AlarmAction
Intent intent = new Intent(AlarmUI.this, AlarmAction.class);
// Create an IntentSender to have the intent executed as a broadcast later when alarm goes off.
PendingIntent sender = PendingIntent.getBroadcast(AlarmUI.this, 0, intent, 0);
/** Schedule the alarm */
// To get any service we use getSystemService(Service Name)
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
/* Finally, we set the alarm to the desired time! WOOHOO! */
alarmManager.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), sender);
}
};
任何想法?先謝謝你。
Thanx修正它。所以出於好奇心,「android:process =」。remote「指定了什麼?另外,Activity現在被調用,但在調用之後,我得到一個錯誤,說我應該使用FLAG_ACTIVITY_NEW_TASK。創建一個好主意每次都有新的任務? – 2010-11-01 14:05:27
我用於掛起的意圖的標誌是FLAG_UPDATE_CURRENT,因此如果已經存在它,它將被覆蓋,以確保我一次只處理一個警報。一旦警報被觸發,我就設置下一個如果有需要的話報警 我假設需要遠程屬性,這樣進程將在您的應用程序外私人啓動..但不是100%確定的。 – Dave 2010-11-01 14:33:05