Three solutions for black screen white screen when Android launches app

Source: Internet
Author: User

You will be very strange, why some apps start, there will be a moment of black screen or white screen to enter the activity interface display, but some apps are not like QQ mobile phone, indeed here to do the processing. Here first understand why this phenomenon, in fact, is very simple, resume a simple example can be understood.

In fact, the black screen or white screen here is not abnormal, but has not yet loaded into the layout file, has shown the window Windows background, black screen white screen is the window background. The code below, you can write a small demo to understand.

@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);//Note: Add 3 second sleep, To ensure a black screen for a while the effect is obvious, in the project application to remove this 3 seconds sleep try {thread.sleep ();} catch (Interruptedexception e) {e.printstacktrace ();} Before this, the black screen or white screen is the background color of window, is the background of Windows, not yet the layout of the interface, to perform setcontentview after the layout setcontentview (r.layout.activity_launcher);}

Where does the window background provide? In the supply theme, the following is a white background, that is, the start-up white screen a moment of color settings.

    <!--application theme. --    <style name= "Apptheme" parent= "Appbasetheme" >        <item name= "Android:windownotitle" >true </item>        <item name= "Android:windowbackground" > @color/white</item>        <!--all Customizations that is not specific to a particular api-level can go here. -    </style>

So, in the theme setting Windowbackground can solve the startup white screen black screen for a while, the following provides three kinds of solutions:

First, provide a. PNG background image

Providing a background map is a solution, but to fit a variety of screens, provide many pictures. Unless the picture is very complex and can only be used in the background map, use this method, otherwise the individual does not recommend.

Second, provide. 9.png (ninepatch) Background image

If the picture is not very complex, can be made ninepatch pictures, then directly make Ninepatch pictures, provide a card can be adapted to any cell phone, why not.

Third, the use of layout-list production background image

If you can use this method, we recommend using this layout-list to make a background image. The first 2 kinds of images used to occupy memory ah, using layout-list compared to save memory, make the app will not say because the volume of the picture becomes larger.

The code is given below.

Launchactivity to start the interface for 3 seconds after the jump to the main page mainactivity, in order to achieve a black screen white screen more obvious effect, before setcontentview the thread sleep 3 seconds.

public class Launcheractivity extends Activity {public final int msg_finish_ launcheractivity = 500;public Handler Mhandler = new Handler () {public void Handlemessage (Message msg) {switch (msg.what) { Case msg_finish_launcheractivity://jumps to mainactivity and ends the current launcheractivityintent intent = new Intent ( Launcheractivity.this, Mainactivity.class); startactivity (intent); finish (); break;default:break;};}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);//Do not display the system's title bar, Ensure that the Windowbackground and interface Activity_main the same size, display in the screen will not be misplaced (remove this line to try to know the effect) GetWindow (). SetFlags ( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//Note: Add 3 seconds to sleep, To ensure a black screen for a while the effect is obvious, in the project application to remove this 3 seconds sleep try {thread.sleep ();} catch (Interruptedexception e) {e.printstacktrace ();} Setcontentview (R.layout.activity_launcher);//stay 3 seconds after sending message, jump to mainactivitymhandler.sendemptymessagedelayed (MSG_ finish_launcheractivity);}} 

Activity_launcher.xml layout file, it is very simple to remember that the linearlayout used in the background is layout_list_start_pic, with the theme theme use the same background, thus eliminating the effect of the background is not the same. The benefits and effects of doing this are not known until you try it yourself.

<linearlayout xmlns:android= ""    xmlns:tools= "http// "    android:layout_width=" fill_parent "    android:layout_height=" Fill_parent    " android:background= "@drawable/layout_list_start_pic" >    <textview        android:layout_width= "Wrap_ Content "        android:layout_height=" wrap_content "        android:textcolor=" #ffffff "        android:text=" @string/ Hello_world "/></linearlayout>

Androidmanifest.xml, note here that the theme used by application is Apptheme, and Launcheractivity uses the theme Startapptheme. The effect of this is that as long as launcheractivity uses the Startapptheme theme, the other activity is apptheme theme.

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= " Android "package=" Com.example.launcheractivity "android:versioncode=" 1 "android:versionname=" 1.0 "> <use S-SDK android:minsdkversion= "8" android:targetsdkversion= "/> <application android:allowb" Ackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:theme= "@st Yle/apptheme "> <activity android:name=".            Launcheractivity "android:label=" @string/app_name "android:theme=" @style/startapptheme "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <cat                Egory android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name= ". Mainactivity "></activity> &LT;/APPLICATION&GT;</manifest> 

styles.xml,2 Theme Settings

<resources xmlns:android= "Http://" > <!--Base application theme, DEP Endent on API level.    This theme are replaced by Appbasetheme from Res/values-vxx/styles.xml on newer devices. --<style name= "Appbasetheme" parent= "Android:Theme.Light.NoTitleBar" > <!--Theme Custom            Izations available in newer API levels can go in res/values-vxx/styles.xml, while customizations related to        Backward-compatibility can go here. -</style> <!--application theme. --<style name= "Apptheme" parent= "Appbasetheme" > <item name= "Android:windownotitle" >true</ite m> <item name= "Android:windowbackground" > @color/white</item> <!--all customizations is not specific to a particular api-level can go here. -</style> <style name= "Startapptheme" parent= "Appbasetheme" > <item name= "anDroid:windownotitle ">true</item> <item name=" Android:windowbackground "> @drawable/layout_list_ Start_pic</item> <!--All customizations this is not specific to a particular api-level can go. -</style></resources>

Layout_list_start_pic.xml Start Page Use this as a background image

<?xml version= "1.0" encoding= "Utf-8"? ><layer-list xmlns:android= " Android >    <!--set the entire screen background to white--    <item >        <color android:color= "@color/white"/>    </item>    <!--Middle Logo--    <item >        <bitmap            android:gravity= "center"            Android : src= "@drawable/ic_launcher"/>    </item>    <!--bottom chart-    <item android:bottom= "10DP" >        <bitmap            android:gravity= "bottom|center_horizontal"            android:src= "@drawable/copyright"/ >    </item></layer-list>

There is also a picture copyright.png

All right, let's do it now.

Start, black screen white screen change this picture look, haha ~

Launcheractivity interface installed after start-up

Adjust to Mainactivity interface

In this way, originally wanted to give GIF animation, with the film Down, AO ao do not know how to send to the computer whining ~ ~ ~ later know can be sent to the Web page ...

Download link later send it up, damn it, going to bed ~~ ~~

Three solutions for black screen white screen when Android launches app

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: 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.