代码及范例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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等软件启动时有一个画面显示进度那样。在此期间程序可以进行初始化工作,减少用户的等待感。