Showing posts with label delay. Show all posts
Showing posts with label delay. Show all posts

Sunday, September 20, 2015

Delay using Handler

private Handler mHandler = new Handler();

private Runnable mUpdateTimeTask = new Runnable() {
        public void run() {
            // do what you need to do here after the delay
            
        }
    };
insert this anywhere you want to run
mHandler.postDelayed(mUpdateTimeTask, 2000);

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();