Android is a timing transmitter in the project, sending it every two hours

In onCreate
@Override
public void onCreate() { super.onCreate(); startTimer(); and register broadcast IntentFilter timerFilter = new IntentFilter(); timerFilter.addAction(Constant.ACTION_TIMER_REQUEST_UP); registerReceiver(myTimerReceiver, timerFilter); } public static long Constant.periodTime = 120 60 1000; protected synchronized void startTimer() { //Define a PendingIntent object, PendingIntent.getBroadcast contains the action of sendBroadcast. Intent intent = new Intent(Constant.ACTION_TIMER_REQUEST_UP); intent.setAction(Constant.ACTION_TIMER_REQUEST_UP); //that is, an intent with action "ACTION_TIMER_REQUEST_UP" is sent













PendingIntent pi = PendingIntent.getBroadcast(this,0,intent,0);
//AlarmManager object, note that this is not a new object, Alarmmanager is a system-level service
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
//Set the alarm clock from Starting from the current time, every time the PendingIntent object pi is executed, pay attention to the relationship between the first parameter and the second parameter
// Send broadcasts through the PendingIntent pi object
am.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis()+Constant.periodTime, Constant. periodTime,pi);
}

Guess you like

Origin blog.csdn.net/Hh19900902/article/details/90747356