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

前端 未结 3 549
悲哀的现实
悲哀的现实 2021-01-15 07:20

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:44

    Maybe you are better of, creating a seperate (Intent)Service and calling it periodically with postDelayed. Create a BroadcastReceiver in your Activity and handle UI changes there.

    Another hint for handling UI changes from other threads: It is not possible. Therefore you need to call runOnUiThread. Here is how to use it

提交回复
热议问题