Saturday, September 19, 2015

Thread/ Sleep for few seconds

anywhere in oncreate
Thread background = new Thread() {
            public void run() {

                try {
                    // Thread will sleep for 3 seconds

                    sleep(6 * 1000);

                    // After 3 seconds redirect to another intent
                    Intent mainmenu = new Intent(getBaseContext(), MainActivity.class);
                    // Use fade in fade out transition animation in startActivity
                    ActivityOptions options = ActivityOptions.makeCustomAnimation(intro.this, R.anim.fade_in, R.anim.fade_out);
                    startActivity(mainmenu,options.toBundle());

                    //Remove activity
                    finish();

                } catch (Exception e) {

                }
            }
        };

        // start thread
        background.start();

No comments:

Post a Comment