我有一个启动画面(徽标活动),显示应用程序启动前3秒的公司名称。我从一个线程开始主要活动,这里是代码:从Splash Screen开始一个活动,我应该使用run()还是runOnUiThread()?
public class Logo extends Activity {
Thread t;
public boolean dead = false;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logo);
t = new Thread() {
public void run() {
try {
Intent i = new Intent(Logo.this, Main.class);
Thread.sleep(3000);
if (!dead) {
startActivity(i);
}
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
t.start();
}
主活动从一个工作线程调用,这是正确的吗?这个代码有什么不同(使用runOnUiThread
)?
...
if (!dead) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Intent i = new Intent(Logo.this, Main.class);
startActivity(i);
}
});
}
...
我看到在调试模式下(相同的线程,相同的操作等)与此代码没有什么区别。哪个是对的?