how to display an activity automatically after 5 seconds

后端 未结 4 1877
梦如初夏
梦如初夏 2020-12-12 23:29

In my application I have created a splash screen type of thing in android. It should remain for 5 seconds. My problem is that how I display another activity automatically af

4条回答
  •  [愿得一人]
    2020-12-13 00:25

    You can use thread here
    For example

    // thread for displaying the SplashScreen
            Thread splashTread = new Thread() {
                @Override
                public void run() {
                    try {
                        int waited = 0;
                        while(_active && (waited < _splashTime)) {
                            sleep(500);
                            if(_active) {
                                waited += 500;
                            }
                        }
                    } catch(InterruptedException e) {
                        // do nothing
                    } finally {
                        finish();
                        // start your activity here using startActivity
                        stop();
                    }
                }
            };
            splashTread.start();
    

提交回复
热议问题