Best way to have a splash screen in an Android application?

后端 未结 6 1286
别跟我提以往
别跟我提以往 2020-12-17 00:40

I need a splash screen for my application. Tried creating an activity having the image for my splash screen; and tried using for loop and the Timer class for introducing a t

6条回答
  •  离开以前
    2020-12-17 01:31

    Try this

    public class SplashActivity extends Activity {
        Handler handler;
        private long timeDelay = 2000; //2 seconds
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.SplashLayout);
            final Intent i = new Intent(this, Landing.class);
            handler = new Handler(); 
            handler.postDelayed(new Runnable() { 
                 public void run() { 
                     startActivity(i); 
                     finish();
                 } 
            }, timeDelay); 
        }      
    }
    

提交回复
热议问题