2013-06-20 39 views
0

我用ArlamManager來創造提醒如何限制時間AlarmManager重複的Android

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); 

am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),10000,sender); 

現在我想從現在開始限制時間重複(2013年6月20日)兩天(2013年6月22日)

感謝

+0

我沒有得到你的問題..請詳細解釋\ – amalBit

+0

你可以在兩天內註冊另一個鬧鐘並在該遊戲中刪除另一個鬧鐘。 –

回答

0

很可能有其他方法可以做到這一點,但在我的腦海裏跳出的第一件事是檢查你的Receiver小號onReceive()方法的日期。如果日期是<的目標日期,然後運行你的代碼,如果沒有則取消報警

當你設置報警,設置要它停止在SharedPreference和運行代碼

前檢查日止
@Override 
public void onReceive(Context context, Intent intent) 
{ 
    SharedPreferences datePref = context.getSharedPreferences("stopDate", 0); 
    // get the current date hear using a Calendar Object and compare it to datePref 
    if (datePref < currentDate) 
    { 
     ... 
    } 
    else 
    { 
     // recreate the PendingIntent and cancel the alarm with AlarmManagers cancel() funciton 
    } 
相關問題