Android Alarm Start startImmediately(Context context, Intent broadcastIntent, int requestCode, long period)

Here you can find the source of startImmediately(Context context, Intent broadcastIntent, int requestCode, long period)

Description

start Immediately

Declaration

@Deprecated
    public static void startImmediately(Context context,
            Intent broadcastIntent, int requestCode, long period) 

Method Source Code

//package com.java2s;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;

public class Main {
    @Deprecated
    public static void startImmediately(Context context,
            Intent broadcastIntent, int requestCode, long period) {
        start(context, broadcastIntent, requestCode, 0, period);
    }/*from   w  w  w.  j  a  v  a 2s. com*/

    @Deprecated
    public static void start(Context context, Intent broadcastIntent,
            int requestCode, long delayAtMillis, long period) {
        PendingIntent sender = genPendingBroadcast(context, requestCode,
                broadcastIntent);
        long currentTime = SystemClock.elapsedRealtime();
        AlarmManager am = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);

        am.cancel(sender);
        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, currentTime
                + delayAtMillis, period, sender);
    }

    private static PendingIntent genPendingBroadcast(Context context,
            int requestCode, Intent broadcastIntent) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
                requestCode, broadcastIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        return pendingIntent;
    }

    public static void cancel(Context context, Intent broadcastIntent,
            int requestCode) {
        PendingIntent sender = genPendingBroadcast(context, requestCode,
                broadcastIntent);
        AlarmManager am = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);
        am.cancel(sender);
    }
}

Related

  1. startAlarm(Context context, int type, int index, int hour, int minute, String action)
  2. startAlarm(Context context, int type, int index, int interval, String action)
  3. startAlarmRing(Context c, String tone)
  4. start(Context context, Intent broadcastIntent, int requestCode, long delayAtMillis, long period)