CountDownTimer更新和阻止 [英] CountDownTimer updating and blocking

查看:89
本文介绍了CountDownTimer更新和阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果正确理解CountDownTimer,则不会在启动它的活动之外的单独线程上运行.那是否意味着如果我在主活动中启动CountDownTimer,然后又在该活动中阻塞另一段代码,是否意味着在线程被捆绑时,CountDownTimer将不再更新?

如果是的话,如果我启动第二个活动,附在主活动上的CountDownTimer也会停止更新吗?

解决方案

如果在主线程中启动CountdownTimer,则主线程中的任何阻塞调用都会延迟OntickOnfinish().

但是第二部分是不正确的,因为即使下一个活动开始了,主线程仍在运行.因此,即使您启动第二个活动,CountdownTimer也将继续运行

If understand CountDownTimer correctly, it doesn't run on a separate thread from the activity that started it. So does that mean if I start a CountDownTimer in my main activity, and another piece of code later blocks in the activity, does this mean the CountDownTimer will no longer update as the thread is tied up?

and if so, would the CountDownTimer attached to the main activity also stop updating if I launch a second activity?

解决方案

If the CountdownTimer is started in the main thread, then any blocking call in the main thread will delay the Ontick and Onfinish().

But the second part is not true, since even if the next activity is started, the main thread is still running. So the CountdownTimer will continue to run even if you launch the second activity

这篇关于CountDownTimer更新和阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆