SoFunction
Updated on 2025-03-02

Android simple method to implement the splash screen

This article describes the simple method of Android to implement the startup screen. Share it for your reference, as follows:

Core code:

package ;
import ;
import ;
import ;
import ;
public class SplashActivity extends Activity {
  private final int SPLASH_DISPLAY_LENGHT = 6000; // Delay for six seconds  @Override
  protected void onCreate(Bundle savedInstanceState) {
    (savedInstanceState);
    setContentView();
    new Handler().postDelayed(new Runnable() {
      public void run() {
        Intent mainIntent = new Intent(,
            );
        (mainIntent);
        ();
      }
    }, SPLASH_DISPLAY_LENGHT);
  }
}

illustrate:

Handler().postDelayed is to delay the specified time before executing

The Handler class can mainly use the following three methods to set the time to execute the Runnable object:

// Execute the Runnable object immediatelypublic final boolean post(Runnable r);
// Execute the Runnable object at the specified time (uptimeMillis)public final boolean postAtTime(Runnable r, long uptimeMillis);
// Execute the Runnable object at the specified time interval (delayMillis)public final boolean postDelayed(Runnable r, long delayMillis);

The following two lines of code start a new activity and close the current activity at the same time.

(mainIntent);
();

For more information about Android related content, please check out the topic of this site:Android programming activity operation skills summary》、《Android resource operation skills summary》、《Android file operation skills summary》、《Summary of Android's SQLite database skills》、《Summary of Android data skills for operating json format》、《Android database operation skills summary》、《A summary of SD card operation methods for Android programming and development》、《Android development introduction and advanced tutorial》、《Android View View Tips Summary"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.