In Android development, we sometimes encounter a program that requires a program to be delayed for a period of time, that is, delayed execution. For example, the app homepage displays a freeze for 3 seconds and then automatically jumps to the login page. How to do this? This article refers to the Internet and compiles a few points for reference for Android developers. I hope it will be helpful to readers.
1. Start a new thread
new Thread(new Runnable(){ public void run(){ (XXXX); (); //Tell the main thread to execute tasks } }).start
2. Use timer
imerTask task = new TimerTask(){ public void run(){ //execute the task } }; Timer timer = new Timer(); (task, delay);
3. Message processing method
new Handler().postDelayed(new Runnable(){ public void run() { //execute the task } }, delay);
4. Using AlarmManager, the specific intention of broadcasting is implemented at all times.