Three writing methods of delayed jump of flash screen page in Android Application

The splash screen page is also called the welcome page. When opening an app, the first thing we see is often a splash screen page. It is called a splash screen page because it will stay for a few seconds after it appears, and then jump to other pages. In addition to making the user experience better, the flash page can also give the app time to initialize data. Here are three ways to write the flash page I summarized.

preparation

Open Android studio, create a new projectmystudy, create a splashactivity, and set it as the startup activity in the manifest file. In the layout file, set the background of splashactivity as a picture (which can be a mobile phone wallpaper).

Then create a homeactivity as the page to jump from the flash page. The layout of homeactivity can simply put a textview:

Method 1: delay sleep in the child thread

This method is very simple. Start a sub thread, sleep for 2 seconds, and then execute the jump code:

Method 2: use handler to send delay message

We can also use the handler to delay sending an empty message, so that the handler will execute the jump code after receiving the message in 2 seconds.

Method 3: use Java timer

Java provides a class: timer, which can play the role of a timer. Its usage is very simple. First, create an external class to inherit TimerTask, override the run () method, and write the code to jump to the page. Then create a timer object and let the modified object call the schedule () method. Schedule () needs to pass in two parameters. The first parameter is the object of mytask, and the second parameter is the delay time.

Complete code

The above is the three writing methods of delayed jump of Android application flash page introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>