Android examples for android.app:Alarm start
restart Alarms
import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.SystemClock; import android.widget.Toast; public class Main { private static final int MINUTES = 2; private static final long TIMEOUT_IN_MILLIS = MINUTES * 60 * 1000; private static PendingIntent sPendingIntent; public static void restartAlarms(Context context) { if (sPendingIntent == null) { Toast.makeText(context, "alarm", Toast.LENGTH_LONG).show(); Intent alarmReceiverIntent = new Intent(context, Main.class); sPendingIntent = PendingIntent.getBroadcast(context, 0, alarmReceiverIntent, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + TIMEOUT_IN_MILLIS, TIMEOUT_IN_MILLIS, sPendingIntent); }/*from ww w . j a v a2s.c o m*/ } }