我正在使用Thread.sleep()
在android中创建一个启动屏幕。 (我知道另一种方法 - 使用 handler
,但我现在必须使用此方法。)
我的代码如下:
public class SplashScreen extends Activity {
Thread t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spash_screen);
new myclass();
}
class myclass implements Runnable{
myclass()
{
t = new Thread();
t.start();
}
public void run()
{
try{
Thread.sleep(1000);
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
finish();
}
catch(InterruptedException e){
System.out.println("thread interrupted");
}
}
}
}
它没有显示任何错误,但启动画面粘在屏幕上。
1秒后,它没有启动另一个 Intent
。
如果您知道错误,请帮助我。
最佳答案
不会调用 runnable 的
run
方法,因为您没有将 runnable 传递给 Thread
构造函数。所以将其传递为:
t = new Thread(this);
关于java - 启动画面粘在屏幕上 - 主要 Activity 未启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25830085/