Android Project Practice (): optimizes the startup page to remove white or black screen for a short time.

Source: Internet
Author: User

Android Project Practice (): optimizes the startup page to remove white or black screen for a short time.

You will find that an empty project is started in seconds when the app is opened from the mobile desktop. However, for self-developed projects, sometimes you will find that when you open the app, there will be a brief 1-2 seconds of white screen or black screen before entering the program interface.

I personally think that many initialization operations are performed in the self-implemented Application file. After these initialization operations are completed, the first Activity is started. This initialization time is because there is no interface, the application displays a white screen or a black screen due to the category of the topic.

  

The cause code for creating a white/black screen is as follows:

 
/**
* @ Author xqx
* @ Email djlxqx@163.com
* Blog: http://www.cnblogs.com/xqxacm/
* CreateAt #/1/30
* Description: initialize a third party.
*/
Public class XApplication extends Application {@ Override public void onCreate () {super. onCreate (); // email initialization // EaseUI. getInstance (). init (this, null); // EMClient. getInstance (). setDebugMode (true); // MobclickAgent of the statistical common scenario of umeng. 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); // analyticdb 6.0.0 and later // The Error Log counts MobclickAgent. setCatchUncaughtExceptions (true); // MobclickAgent for page access path statistics. openActivityDurationTrack (true); // Aurora JPushInterface. setDebugMode (true); JPushInterface. init (this );
    
/... Various third-party initialization}

 

Solution: set a different topic for the first Activity of the application. Generally, the first Activity is the startup page.

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

  

<! -- Base application theme. --> <! -- Topic 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 = "col1_cent "> @ color/col1_cent </item> </style> <! -- Enable the page Activity topic to solve the white screen issue of 1-2 seconds when enabling. It inherits from the application topic and only needs to set this topic for the first Activity of the application, generally, this is the startup page --> <style name = "MyGuideTheme" parent = "AppTheme"> <! -- Customize your theme here. --> <item name = "android: javaswistranslucent"> true </item> <item name = "android: windowNoTitle"> true </item> </style>

  

In the AndroidManifest. xml file, set this topic on 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 topic separately> <intent-filter> <action android: name = "android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> </activity>

  

Note: 1. This solution has a bug where the Activity of the topic is set on the small part model. If the user enters the latest list (press the home key or the menu key) flash may occur.

Therefore, we cannot set the topic of the entire application as this. We only need to set the startup page, because the startup page only takes a few 1-2 seconds to enter the main interface, and the trigger possibility of users entering the latest list is extremely low, good experience.

2. If the Application initializes many objects for a long time, for example, more than 2 seconds, this method is not applicable, resulting in the user clicking icon2 seconds before opening the app, the user experience is poor.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.