我一直在開發一個Android應用程序,我需要每小時執行一項任務。我使用下面的代碼是:如何每小時執行一項任務?
private static final long ALARM_PERIOD = 1000L;
public static void initAlarmManager(Context context) {
Editor editor=PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putBoolean(context.getString(R.string.terminate_key), true).commit();
AlarmManager manager = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
Intent i = new Intent(context, AlarmEventReceiver.class);
PendingIntent receiver = PendingIntent.getBroadcast(context, 0, i, 0);
manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime(), ALARM_PERIOD, receiver);
}
它爲我,但我的客戶告訴我,該任務只能1次,並會無法正常工作1小時。我在哪裏犯了一個錯誤?請告訴我。謝謝。
接受一些答案 – user1378730