I need to do service every night at midnight. I would like to use AlarmManager for this.
Can you give me some tips on how to make it work correctly?
alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, System.currentTimeMillis(), AlarmManager.INTERNAL_DAY, serviceIntent);
Perhaps I need to use the Calendar object to indicate the time? Thanks for any help!
setInexactRepeating(), as the name suggests, is inaccurate. Keep in mind that it can start somewhat before or after midnight.
setInexactRepeating()
, , Calendar. getDate(), Date getTime() Date, setInexactRepeating().
Calendar
getDate()
Date
getTime()
, , "setInexactRepeating". : alarmManager.setRepeating(RTC_WAKEUP, ...), Calendar , .
alarmManager.setRepeating(RTC_WAKEUP, ...)
, , , , RTC_WAKEUP RTC. , , RTC_WAKEUP, , , , .
RTC_WAKEUP
RTC
Source: https://habr.com/ru/post/1747773/More articles:Программно загружать данные в solr, используя solrj и java - javaSticky Footer Issues - cssSpark VS 2010 intellisense - asp.net-mvcPhusion passenger on ubuntu 10.04: why apache2-prefork-dev when we want apache2-mpm-worker? - ruby | fooobar.comHow to handle activity lifecycle using sockets in Android? - androidАвтоматическое тестирование для оболочки SDK для Facebook - phpIs it safe on a production server? - javaHow to configure hbm2java maven2 plugin to create POJO for all mapping files - maven-2Why does this list comprehension not do what I expect from it? - pythonAndroid graphics library Android - androidAll Articles