它是安全启动和活动从非UI线程?它是、线程、安全、UI

2023-09-04 08:42:36 作者:心囚

假设我的活动UI线程生成一个单独的线程在一些点。它是安全的新的线程来断火的意图展开新的活动?

Suppose my activity ui-thread spawns a separate thread at some point. Is it safe for that new thread to fire off an Intent for launching a new activity?

感谢

推荐答案

我可能是错的,但我觉得 startActivity()内部在UI线程中执行。所以,是的,它应该是安全的。

I could be wrong, but I think startActivity() internally executes in the UI thread. So yes, it should be safe.

如果你想成为100%的把握,调用你的 startActivity()在活动的 runOnUiThread()作为一个的Runnable

If you wanted to be 100% sure, invoke your startActivity() in your activity's runOnUiThread() as a Runnable.