android app cold start

1. Set the background image to the logo image of our APP as a guide for APP startup. Now most of the APPs on the market do this.

  <style name="AppWelcome" parent="AppTheme">
        <item name="android:windowBackground">@mipmap/bg_welcome_start</item>
    </style>

2. Set the background color to transparent color, so that when the user clicks on the desktop APP picture, they will not "immediately" enter the APP, and stay on the desktop for a while. In fact, the APP is already started at this time, but we have a scheming I set the color of the windowBackground in Theme to be transparent, and forcibly threw the pot to the mobile phone application manufacturer (the mobile phone response is too slow, haha), in fact, now WeChat, QQ space also do this.

<style name="Appwelcome" parent="android:Theme.Translucent.NoTitleBar.Fullscreen"/>

One thing to note about transparency is that if you directly introduce Theme into Activity, the following exceptions may occur when running:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

This is because an incompatible Theme is used. For example, my Activity here inherits AppCompatActivity. The solution is very simple:
1. Let its Activity integrate Activity instead of the compatible AppCompatActivity
2. Super.onCreate in the onCreate() method (savedInstanceState) Set the Theme of our original APP before

public class MainActivity extends AppCompatActivity {    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            setTheme(R.style.AppTheme);            
            super.onCreate (savedInstanceState);
    }
}
For the above two methods, we need to introduce Theme into the corresponding Activity

  <activity
            android:name=".app.main.MainActivity"
            android:theme="@style/AppWelcome"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325941343&siteId=291194637