问题
I have set alarm for 1 minutes but it called after every 5 minutes.
AlarmManager alarmManager = (AlarmManager)getActivity().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getActivity(), MyBroadcastReceiver.class);
intent.setAction("com.example");
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); //pending intent
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, new Date().getTime(), 60000, pendingIntent); //time duration is 60 seconds
回答1:
USE alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, new Date().getTime(), 60000, pendingIntent); //time duration is 60 seconds Instead of alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, new Date().getTime(), 60000, pendingIntent); //time duration is 60 seconds
来源:https://stackoverflow.com/questions/38865893/set-alarm-for-1-min-but-it-called-after-5-minutes