2011-04-26 71 views
0

我設置了一個AlarmManager,它會在一段時間後重復發出警報。我爲此使用了以下代碼。Android AlarmManager執行時間問題

Intent intent = new Intent(ViewDoughnut.this, NotificationMessage.class); 
PendingIntent sender = PendingIntent.getBroadcast(ViewDoughnut.this, 0, intent,PendingIntent.FLAG_CANCEL_CURRENT); 

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); 
am.setRepeating(AlarmManager.RTC_WAKEUP,nextAlarmTime, alarmInterval, sender); 

現在要在鬧鐘的時候執行正確的工作,我已經創建了以下擴展BroadcastReceiver的類。現在我需要以毫秒爲單位的時間,當警報工作應該在該類中執行時。如何得到它?

public class NotificationMessage extends BroadcastReceiver { 
    // Display an alert that we've received a message. 
    // @Override 
    public void onReceive(Context context, Intent intent) { 

     // here I need the time when the alarm should execute. 
    } 
} 

在這裏我想補充,系統時間是不是爲我工作,因爲如果該設備是在警告時關掉,它執行的是當設備在此時間之後開啓。但我需要時間來執行它。

回答

0

您可以創建一個派生自保存所有全局變量的Application的類。然後只需設置一個長變量來保存時間,然後再初始化鬧鐘

+0

這對我的情況不會有效,因爲它是一個重複鬧鐘,並且多個鬧鐘對於不同事件同時有效。 – 2011-04-26 13:36:33