Demo Appオープン時の静止画の展示を継続

2859 ワード

多くのAppは開き始めたばかりの頃、静的な画像が数秒続く効果があります.小さなdemoで実現を覚えてみましょう.
public class WelcomeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        requestWindowFeature(Window.FEATURE_NO_TITLE);//     
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);
        class ThreadWelcome extends Thread{//       
            public void run(){
                try {
                    ThreadWelcome.sleep(3000);//  2 
                    Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                    startActivity(intent);
                    finish();//       activity           onDestory()             
                    } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

        }
        new ThreadWelcome().start();//       
// new Thread(){
// @Override
// public void run() {
// try {
// Thread.sleep(2000);
// Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
// startActivity(intent);
// finish();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// }.start();
    }

}

上に2つの実装スレッドの方法を示した1つは,newの1つのオブジェクトを直接継承してこのプログラムに比較的詳細な注釈を付けることであり,今後の開発において大きな参考になるはずである.