开发者

Does a thread safe timer exist?

开发者 https://www.devze.com 2023-01-06 16:53 出处:网络
Is there another equivalent of Timer for android which is thread开发者_开发百科 safe? Using the timer causes problems in my application while updating the gui, most of the time it complains that gui i

Is there another equivalent of Timer for android which is thread开发者_开发百科 safe? Using the timer causes problems in my application while updating the gui, most of the time it complains that gui is being updated from another thread, i tried using handlers but that didn't fix the problem.


Use postDelayed() on any of your Views. Have it do its work then call postDelayed() again.

Or, use runOnUiThread() instead of messing with your own Looper/Handler.

Or, create your Handler as a private data member of the class with an ordinary initializer -- it would appear you are trying to create it in the background thread, which will not work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号