[英]Android:: Blocking main thread for worker thread to finish before executing other tasks in main thread
[英]Android: What happens if the main thread is finished before the worker thread
为了实现我的应用程序的初始屏幕,我从主线程启动了一个线程,该线程sleep
s一段时间并调用home意图。 并且工作正常。 但我担心的是,我们需要等待主线程吗? (当前我没有这样做)如果主线程首先完成,将会发生什么以及如何处理这种情况?
谢谢,Venkat
将此代码用于启动画面:
Handler handler=new Handler();
Runnable r=new Runnable()
{
public void run()
{
// start another activity
}
};
handler.postDelayed(r, 5000); // wait 5 second
主线程本身不能“等待”。 当仍有非守护程序子线程仍在运行时,应用程序无法退出。
如果在启动子线程之前将它们设置为守护程序,则它们将在应用程序退出时立即终止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.