Android project combat (forty-two): startup page optimization, remove short white screen or black screen

Original: Android project combat (forty-two): startup page optimization, remove short white screen or black screen

  You will find an empty project, and opening the app from the mobile desktop starts in seconds. But for projects developed by myself, sometimes I find that when I open the app, there will be a white screen or a black screen for a short period of 1-2 seconds, and then I enter the program interface.

  Personally, I understand that there are many initialization operations in the Application file that we have implemented. When these initialization operations are completed, we enter the first Activity. Because there is no interface during this initialization time, the application will be displayed because of the theme category. White or black screen.

  

  The reason codes for what constitutes a white/black screen are as follows:

 
 
/** 
* @author xqx
* @email [email protected]
* blog:http://www.cnblogs.com/xqxacm/
* createAt 2017/1/30
* description: Perform third-party initialization and other operations
*/
public class XApplication extends Application{
    @Override
    public void onCreate() {
        super.onCreate();

//EaseUI.getInstance().init(this,null         )
 ;          //EMClient.getInstance().setDebugMode(true
         ) ;

        // Youmeng statistics general statistics scene type 
        MobclickAgent.setScenarioType( this , MobclickAgent.EScenarioType. E_UM_NORMAL);
         // Disable the default page statistics method, so that the Activity will not be automatically counted. 
        MobclickAgent.openActivityDurationTrack( false ) ;
         // Log encryption 
        MobclickAgent.enableEncrypt( true ); // Version 6.0.0 and later
         // Error log statistics 
        MobclickAgent.setCatchUncaughtExceptions( true );
         // Page access path statistics 
        MobclickAgent.openActivityDurationTrack( true ) ;

        // 极光
        JPushInterface.setDebugMode(true);
        JPushInterface.init( this ); /....Various 
    
     tripartite initialization  }

 

  The solution is to set a different theme for the first Activity of the application. Generally, the first Activity is the startup page.

  We only need to write a theme in the res/values/styles.xml file that inherits from the theme of our application

  

    <!-- Base application theme. -->
    <!-- The theme of the application. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

   <!--Startup page Activity theme, to solve the white screen problem of 1-2 seconds when opening, inherited from the theme of the application, you only need to set this theme for the first Activity of the application, usually the startup page--> 
    <style name= " MyGuideTheme " parent= " AppTheme " >
        <!-- Customize your theme here. -->
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowNoTitle">true</item>
    </style>

  

  Then in the AndroidManifest.xml file, you can set this theme for the startup page.

  

    <activity
            android:name = " .ui.moduleLogin.GuideActivity " 
            android:configChanges = " orientation|keyboardHidden|screenSize " 
            android:screenOrientation = " portrait " 
            android:theme="@style/MyGuideTheme" // This Activity sets the theme separately
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

  

  Note: 1. There will be a bug in this solution. If the Activity of the theme is set on a small part of the model, if the user enters the recent list (long press the home button or press the menu button), there will be a flickering problem.

        So we can't set the theme of the whole application to this, only need to set the startup page, because the startup page only takes a few 1-2 seconds to enter the main interface, the possibility of triggering the user to enter the recent list is extremely low, and the experience is better.

        2. If there are many things initialized in the Application and the time is long, such as more than 2 seconds, this method is not applicable, it will cause the user to click the icon for 2 seconds before opening the app, and the user experience is not good.

 

Guess you like

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