简体   繁体   中英

Time scheduling by using alarm manager

I have a AutoUpdate service class, oncreate()- I create the log file in externalsdcard onStartCOmmand()- UpdateTask= new UpdateTask(this,AutoUpdate.logwriter) I have a UpdateTask class which extends thread class- in this class in run method I write all the data in the log file by creating a local HTTP context and at the end I put Thread.sleep(3000). Right now I get data in the log file for every 3 seconds but I want to change the time limit to 15 min I have the BootReceiver class extends BroadcastReceiver : I pass an intent to AutoUpdate Service class on boot and start the service. My Question was I need to put the alarm manager where for every 15 min UpdateTask should work and write the data in logs for every 15 min other than the thread I have it working for 3 seconds by using Thread.sleep(3000)

I need to replace the sleep thread with alarm manager

Reference: I want to update the data from server by giving a time limit

When you schedule the alarm manager to run repeatedly, it will automatically call the intent in your pending intent per interval (15 mins in your case).

In that case you would not need a on going service instead implement what you should do is implement the logging login in an IntentService's onHandleIntent method and pass it a PendingIntent to be started by the AlarmManager.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM