由网友(逞不完的强)分享简介:我收到错误与此code。为什么忽忽123123123 发定时器=新的Thread(){公共无效的run(){尝试{睡眠(1500);splash.setImgeResource(R.drawable.dilclogo);睡眠(1500);}赶上(InterruptedException的E){e.printStac...![易班用户更换手机号操作流程 学生篇](/d/file/2023/09-17/82b0804bd4b9e193c053e15324ec14f8.png)
我收到错误与此code。为什么忽忽 123123123
发定时器=新的Thread()
{
公共无效的run()
{
尝试
{
睡眠(1500);
splash.setImgeResource(R.drawable.dilclogo);
睡眠(1500);
}
赶上(InterruptedException的E)
{
e.printStackTrace();
}
最后
{
意向意图=新的意图(MainActivity.this,MenuScreen.class);
startActivity(意向);
}
}
};
timer.start();
解决方案
这是因为你不能直接从任何其他线程访问UI /主线程。您可以使用下面的方法,虽然访问您的UI线程:
使用的AsyncTask
使用 runOnUiThread()
![易班用户更换手机号操作流程 学生篇](/d/file/2023/09-17/82b0804bd4b9e193c053e15324ec14f8.png)
您还可以阅读 这 在线程文章的android 的帮助你理解这个概念比较好。
I'm getting error with this code. Why huhu 123123123
Thread timer = new Thread()
{
public void run()
{
try
{
sleep(1500);
splash.setImgeResource(R.drawable.dilclogo);
sleep(1500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent intent = new Intent(MainActivity.this, MenuScreen.class);
startActivity(intent);
}
}
};
timer.start();
解决方案
This is because you can NOT access your UI/Main thread directly from any other thread. You can use below methods to access your UI thread though:
UsingAsyncTask
Using runOnUiThread()
You can also read this article on threading in android to help you understand this concept better.
相关推荐
最新文章