你能告诉我如何在android中使用Timer显示启动画面。我可以使用线程显示,但是线程是不错的选择,你能告诉我处理这个问题的最佳方法吗?像这样使用线程
包 com.example.splash_test;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
public class MainActivity extends Activity {
protected int _splashTime = 5000;
private Thread splashTread;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
splashTread = new Thread() {
@Override
public void run() {
try {
synchronized(this){
wait(_splashTime);
}
} catch(InterruptedException e) {}
finally {
finish();
Intent i = new Intent();
i.setClass(MainActivity.this, SecondActivity.class);
startActivity(i);
//stop();
}
}
};
splashTread.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}