0

so i got this alarm manager that can be triggered by a intentService with BOOT_COMPLETED..

the alarm manager work is to call another intent service every 10 mins.. this intent service updates an SQLite database value..

7:00  = boot time, alarm manager set up
7:10 = intent service called, increment a value in SQLITE, "Week" column, from value 1 to 2
7:20 = same as above, value 2 to 3
7:21 = turn off the phone..
7:22 = turn on the phone, set up the alarm manager again
7:30 = same as 7:10 and 7:20 function, 3 to 4
7:31 = turn off again
7:55 = turn on again, the function that should be off twice, (7:40 and 7:50) but it only goes off once, meaning the value was change from 4 to 5, instead of 4 to 5 to 6..

every change of week, the intent service do other things depending on the number, i should never skip any week

@Override
public void onReceive(Context context, Intent intent) {
    PowerManager pm = (PowerManager) context
            .getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(
            PowerManager.PARTIAL_WAKE_LOCK, "");
    wl.acquire();

    // Put here YOUR code.
    Toast.makeText(context, "Alarm !!!!!!!!!!", Toast.LENGTH_LONG).show(); // For
                                                                            // example

    wl.release();
    context.startService(new Intent(context, CheckClassroom.class));

    SharedPreferences a = context.getSharedPreferences("mPref", 0);
    SharedPreferences.Editor editor = a.edit();
    long interval = System.currentTimeMillis();
    editor.putLong("first", interval + (30 * 1000));
    int idnow = a.getInt("idnow", 1);
    idnow = idnow + 1;
    editor.putInt("idnow", idnow);

    editor.commit();

}

public void SetAlarm(Context context) {
    SharedPreferences a = context.getSharedPreferences("mPref", 0);

    long iFirst = a.getLong("first", System.currentTimeMillis()
            + (30 * 1000));


    AlarmManager am = (AlarmManager) context
            .getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, Alarm.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);

    am.setRepeating(AlarmManager.RTC_WAKEUP, iFirst, 30 * 1000, pi); // 
}
mcr619619
  • 435
  • 1
  • 4
  • 13
  • can you show your Alarm.class and where have you done the logging that is show in the log above. – Ashwin Nov 15 '12 at 02:52
  • the code above is the alarm class, i dont have logs.. dont know how to do it – mcr619619 Nov 15 '12 at 03:02
  • where is the setAlarm() called? – Ashwin Nov 15 '12 at 03:05
  • setAlarm will be called right after the phone boot..sorry for late reply, i had class – mcr619619 Nov 15 '12 at 11:08
  • 1
    Are you sure that the alarm executes atleast once after boot up? – Ashwin Nov 15 '12 at 11:33
  • yes, it is done via another service with BOOT_COMPLETED action.. it only run once, no matter how many cycle has been passed that the phone is off, once i turn it on, it only executes the "DB updating" once. – mcr619619 Nov 15 '12 at 12:40
  • 1
    put this line of code in the function setAllarm() - Log.v("in setAlarm","here");' The see if this shows up in the logcat – Ashwin Nov 15 '12 at 13:51

0 Answers0