Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Alarmmanager to start a service at specific time
    primarykey
    data
    text
    <p>I have searched a lot of places but couldnt find a clean sequential explanation of how to start a service (or if thats not possible then an activity) at a specific time daily using the AlarmManager??</p> <p>I want to register several such alarms and triggering them should result in a service to be started. I'll be having a small piece of code in the service which can then execute and i can finish the service for good....</p> <pre><code>Calendar cal = Calendar.getInstance(); Calendar cur_cal = Calendar.getInstance(); cur_cal.setTimeInMillis(System.currentTimeMillis()); Date date = new Date(cur_cal.get(Calendar.YEAR), cur_cal.get(Calendar.MONTH), cur_cal.get(Calendar.DATE), 16, 45); cal.setTime(date); Intent intent = new Intent(ProfileList.this, ActivateOnTime.class); intent.putExtra("profile_id", 2); PendingIntent pintent = PendingIntent.getService(ProfileList.this, 0, intent, 0); AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE); alarm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pintent); System.out.println("The alarm set!!"); </code></pre> <p>i tried this code to activate the alarm at 4.45... but its not firing the service... do i have to keep the process running?? M i doing anything wrong???</p> <p>One more thing, my service gets perfectly executed in case i use the following code:</p> <pre><code>long firstTime = SystemClock.elapsedRealtime(); alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 30*1000,pintent); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload