创建程序启动屏幕

代码及范例:

public class Splashscreen extends Activity {
	protected int _splashTime = 200;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		//setContentView(R.layout.splash);
		startActivity(new Intent(Splashscreen.this, Ankicard.class));

		Thread splashTread = new Thread() {
			@Override
			public void run() {
				try {
					int waited = 0;
					while ((waited < _splashTime)) {
						sleep(100);
						waited += 100;
					}
				} catch (InterruptedException e) {
					// do nothing
				} finally {
					finish();
					startActivity(new Intent(Splashscreen.this, Ankicard.class));
					stop();
				}
			}
		};
		splashTread.start();
	}
}

说明:通过新建一个线程来创建一个splash screen,效果就如同电脑上Office、Photoshop、Media Go等软件启动时有一个画面显示进度那样。在此期间程序可以进行初始化工作,减少用户的等待感。