Implementation and application of Android startup page optimization

  • 2021-12-12 09:58:08
  • OfStack

When Android applies cold start, It needs to start from Application, and the loading time will be relatively long. During this time, all users can see is a "white screen" (this is because the default android: windowBackground of AppTheme is set to white by default). Therefore, I think the real startup page should be a page created by us instead of a "white screen" when users click on the application.
In this way, users who don't know the truth intuitively feel that the application can be opened in seconds.

1. First create a new splash_screen. xml file in the drawable directory


<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="opaque">
    <item android:drawable="@color/colorPrimary"/>
    <item>
        <bitmap android:src="@drawable/ic_logo"
            android:gravity="center"/>
    </item>
</layer-list>

We use the layer-list tag to create a layer list, which is actually an LayerDrawable, set a background, and then put the application icon. This is the startup page I want to show, which can be defined according to my own needs.

2. Then define an SplashTheme in the style. xml file


<resources>
    ...
    
    <style name="SplashTheme" parent="AppTheme">
        <item name="android:windowBackground">@drawable/splash_screen</item>
    </style>

</resources>

All you need to do here is set the window background to LayerDrawable that we just defined.

3. Then we need to set our main page, android for MainActivity in the AndroidMenifest. xml file: theme to the SplashTheme we defined


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
      ...
      >

    ...

    <application
        ...
         >
        <activity
            android:name=".activity.MainActivity"
            android:launchMode="singleTask"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        ...
    </application>

</manifest>

Isn't it very simple? That's it

The above is the Android startup page optimization of the implementation of the application of seconds open details, more about Android implementation of the application of seconds open information please pay attention to other related articles on this site!


Related articles: