从非ui线程启动活动是否安全? [英] Is it safe to launch an activity from a non-ui thread?

查看:67
本文介绍了从非ui线程启动活动是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的活动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%确定,请在活动的runOnUiThread()中将您的startActivity()调用为Runnable.

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

这篇关于从非ui线程启动活动是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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