Code example for WakefulBroadcastReceiver

Methods: startWakefulService

1
  private static final int INITIAL_DELAY=5000; // 5 seconds
 
  @Override 
  public void onReceive(Context ctxt, Intent i) {
    if (i.getAction() == null) {
      startWakefulService(ctxt,
                          new Intent(ctxt, ScheduledService.class));
    } 
    else { 
      scheduleAlarms(ctxt);
    } 
  } 
 
  static void scheduleAlarms(Context ctxt) {
    AlarmManager mgr=
        (AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);
    Intent i=new Intent(ctxt, PollReceiver.class);
    PendingIntent pi=PendingIntent.getBroadcast(ctxt, 0, i, 0);
 
    mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
Contextual code suggestions in your IDE  Get Codota for Java