Android Repetitive Task

前端 未结 3 1763
猫巷女王i
猫巷女王i 2020-12-18 01:47

In an Activity, I need to call a web service every 30 seconds or so, and use the data to update the UI.

Is there a recommended approach on how to schedule a repetiti

相关标签:
3条回答
  • 2020-12-18 01:51

    If this is in a running activity, you could use Timer/TimerTask and a Handler, or you could use postDelayed() and an AsyncTask.

    0 讨论(0)
  • 2020-12-18 02:06

    You will want to create a Handler. Here is a brief code example.

    0 讨论(0)
  • 2020-12-18 02:14

    Make sure to acquire the WakeLock if you want this to be running after the screen is turned off (or more accurately, to prevent the CPU from shutting down). Use of AlarmManager is another alternative.

    0 讨论(0)
提交回复
热议问题