Home > Mobile >  In Android AlarmManager timer setting time invalid problem?
In Android AlarmManager timer setting time invalid problem?

Time:11-23

Public static void startPullingService (Context Context, int seconds, Class<?> CLS, String action) {
//get AlarmManager system service
(AlarmManager AlarmManager manager=) context. GetSystemService (context. ALARM_SERVICE);
//packaging need to perform a service of intent
Intent Intent=new Intent (context, CLS);
Intent. SetAction (action);
PendingIntent PendingIntent=PendingIntent. GetService (context, 0, intent, PendingIntent. FLAG_UPDATE_CURRENT);
//the start time of trigger service
Long triggerStartTime=SystemClock. ElapsedRealtime ();
//use AlarmManger setRepeating method set periodic execution time interval (seconds seconds) and the need to perform a Service
Manager. SetRepeating (AlarmManager ELAPSED_REALTIME, triggerStartTime + seconds (* 1000), 1000 seconds * and pendingIntent);

Above is I start a timer notification to implement information push service, set the time interval in the setRepeating, I set is 1 * 1000, but why no matter this value will be set on the simulator, hint at a time is 1 minute

CodePudding user response:

Because from the beginning of the Android5.1, in order to optimize the power, the lowest polling time is a minute!

CodePudding user response:

AlarmManager is outdated, can consider the WorkManager for background on timer or alarm clock in the high version of the mobile phone will not take effect
  • Related