Execute function after 5 seconds in Android

后端 未结 9 1009
既然无缘
既然无缘 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

    You can use the Handler to add some delay.Call the method displayData() as below so that it will be executed after 5 seconds.

    new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
              displayData();
            }
        }, 5000);
    

    Note : Do not use the threads like Thread.sleep(5000); because it will block your UI and and makes it irresponsive.

提交回复
热议问题