How to run an async task for every x mins in android?

前端 未结 9 1055
长发绾君心
长发绾君心 2020-11-27 12:28

how to run the async task at specific time? (I want to run it every 2 mins)

I tried using post delayed but it\'s not working?

    tvData.postDelayed         


        
9条回答
  •  执念已碎
    2020-11-27 13:02

    When phone goes to sleep mode, to save battery, and it is quite possible to happen within 2 mins interval, Handler.postDelayed() may miss scheduled time. For such activities you should use AlarmManager, get a lock with PowerManager to prevent going to sleep back while you're running the AsyncTask.

    See my post with code sample here

    Also you may want to read Scheduling Repeating Alarms

提交回复
热议问题