Android: Create a background thread that runs periodically and does UI tasks?

前端 未结 3 1262
遇见更好的自我
遇见更好的自我 2021-01-15 07:03

OK, so I know how to do a backround task, I know how to do a periodic task (using handle postdelayed and runnable), I also know how to do UI task from background thread (via

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-15 07:29

    If activities are frequently switching, why not reversing the responsibilities. You might create a service which executes a periodic network task.

    Then, - either your activities periodically call this service to get the value. - or you use a listener system : you create an interface that your activities must implement in order to get notified from the task completion

提交回复
热议问题