Android Startup Page White Screen Solution

  • 2021-12-11 08:52:06
  • OfStack

When we open app, will there be a white screen for 1 moment and then enter the main activity? Although this will not cause any bad consequences, it feels that the user experience is not very good. Like NetEase Cloud Music, etc., their loge is displayed in an instant when it is opened, which is seamless and has no white screen. How can it be done?

At first, my thinking is like this. Maybe because we have too much main activity logic, the load will slow down, resulting in a white screen. If you use an activity that displays only one local picture, will it not display a white screen? Without saying much, let's try 1 time:

Code in Activity:


/**
 *  Startup page, showing the logo , pause 2 Jump after seconds 
 */
public class LunchActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_lunch);

    // Open a child thread to pause. If you pause in the main thread, it will cause the main page to get stuck, so in the sub-thread sleep Jump in two seconds 
    new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        start();
        LunchActivity.this.finish();
      }
    }).start();
  }
  // Jump to the main page 
  private void start(){
    Intent intent = new Intent(LunchActivity.this,MainActivity.class);
    startActivity(intent);
  }
}

Code in layout:


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#e74b37"
  tools:context=".LunchActivity">

  <ImageView
    android:id="@+id/imageView5"
    android:layout_width="80dp"
    android:layout_height="80dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.31"
    app:srcCompat="@drawable/icon" />
</android.support.constraint.ConstraintLayout>

Here, simply specify an imageView to display a picture. And set the background to orange

Finally, set the startup page activity as the main activity:


<activity android:name="com.example.qinglv.LunchActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>

I really want to be very good. After I finish, I open it and see it. It will still be a white screen. What's going on?

The loading of activities takes time. Simple activities will take less time, but there will be a white screen for 1 moment. So what is this white screen? Is the background of every activity. When you open an activity, because the content has not been loaded, it is only the background, so we just need to change the background and set it to the one logo photo we need. How to set it up?

The background is specified in the theme. First, set a theme and change the background to what we want. 1 and our startup page remain 1, so that it won't look like two startup pages. Like NetEase Cloud Music, the background is set to logo, but the startup page is to put advertisements, but this will affect the user experience (it is understandable to advertise for revenue). Look at the code:

In res-value-styles:


<style name="NewAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
   <!-- Customize your theme here. -->
   <item name="colorPrimary">@color/colorPrimary</item>
   <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
   <item name="android:windowBackground">@color/colorPrimary</item>
   <item name="colorAccent">@color/colorAccent</item>
 </style>

The point is this sentence <item name="android:windowBackground">@color/colorPrimary</item>
Here I specify 1 color, you can also specify 1 picture

Then specify the theme for the startup page activity:

In: AndroidManifest:


<activity android:name="com.example.qinglv.LunchActivity"
     android:theme="@style/NewAppTheme">
     <intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
   </activity>

The point is this sentence android:theme="@style/NewAppTheme"

Then when you open it again, you will find that it won't. The white screen originally displayed became the picture we set up.

The above is the Android startup page white screen solution details, more about the Android startup page white screen information please pay attention to other related articles on this site!


Related articles: