2014-01-25 24 views
1

我只是不能將我的警報解僱。關於重新啓動後取消,保存和恢復的所有問題已經得到了解決。只是在預期的時間沒有任何事情發生。我試圖開始一個活動,而不是服務,但沒有任何區別。其實,我想知道一點,因爲它沒有說服務對象不僅應該創建,而且要開始。這是自動的,因爲類型?從Activity直接調用startService()可以正常工作,所以問題出在Alarm上,而不是在Service中。很遺憾,當前應用程序設置的警報無法列出來檢查是否一切正常。Android:如何從預定警報啓動服務?

任何幫助表示讚賞。

long INTERVAL_WEEK = AlarmManager.INTERVAL_DAY * 7; 
DateFormat df = new SimpleDateFormat("E, yyyy-MM-dd'T'HH:mmZ"); 
Log.d(TAG, "next alarm " + df.format(cal.getTime())); // checking the right time 
Intent showNotificationIntent = new Intent(context, MyNotificationService.class); 
alarmIntent = PendingIntent.getBroadcast(context, dayOfWeek, showNotificationIntent, 0); 
getAlarmManager(context).setInexactRepeating(AlarmManager.RTC, cal.getTimeInMillis(), 
    INTERVAL_WEEK, alarmIntent); 

回答

1

創建PendingIntent時,您應該使用PendingIntent.getService()而不是PendingIntent.getBroadcast()。

+0

太好了。我不明白爲什麼有各種get ...()方法。謝謝! –