Execute function after 5 seconds in Android

后端 未结 9 1011
既然无缘
既然无缘 2020-12-13 12:39

I am new in android development and now my launcher activity show only 5 seconds and after that I want to check the user is logged in or not function and perform the actions

9条回答
  •  爱一瞬间的悲伤
    2020-12-13 13:31

    Use a CountDownTimer

    // There's a TextView txtCount in Main Activity
    
    final int secs = 5;
    new CountDownTimer((secs +1) * 1000, 1000) // Wait 5 secs, tick every 1 sec
    {
        @Override
        public final void onTick(final long millisUntilFinished)
        {
            txtCount.setText("" + (int) (millisUntilFinished * .001f));
        }
        @Override
        public final void onFinish()
        {
            txtCount.setText("GO!");
            finish();
            // Time's up - Start the Login Activity
            final Intent tnt =
                new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(tnt);
        }
    }.start();
    

提交回复
热议问题