Solution to screen and black screen of Android Splash interface _android

Source: Internet
Author: User

Objective

I believe a lot of Android developers have encountered this requirement:

1. Implementation of a splash interface, the interface has application-related background picture and a Start button.
2. Click on the button to enter the home page, the user then open the application will not show this splash interface.

Also believe that a lot of students have encountered such confusion:
• The second entry into the application, although you have been directly to the splash interface to the home page, but there is a white screen or black screen or with actionbar white screen flash.

If you also have this problem, read the article, and I will take you to analyze and solve the problem.

Solution

Here we first give the solution, and then analyze the reason why. Avoid the analysis of the large section of text hindered the enthusiasm of the students to study.

The solution is very simple, in a nutshell: Set a theme for splash activity, the theme is: Full screen + transparent.

Style.xml Add Splashtheme Theme:

<style name= "Splashtheme" parent= "Apptheme" >
  <item name= "Android:windowfullscreen" >true</item >
  <item name= "android:windowistranslucent" >true</item>
</style>

Androidmanifest.xml for splashactivity configuration topics:

<activity android:name= ". Activity. Splashactivity "
  android:theme=" @style/splashtheme ">
  <intent-filter>
    <action android: Name= "Android.intent.action.MAIN"/>

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

After the configuration, you screen, black screen, actionbar screen should have vanished. In order to know it, and know why, I hope that students can continue to work with me to analyze the causes of these white screen.

The window initiation process for the activity component

First of all, this paragraph contains a large number of references to the Luo Shenyang Teacher's blog. In order to facilitate understanding, the content of its compression. If tort, I immediately delete this section of analysis ha.

To understand the root cause of screen, you have to track the window initiation process for the activity component. The activity component invokes the Idiom function startactivitylocked method of the Activitystack class during the startup process. Note that when invoking the Idiom function startactivitylocked method of the Activitystack class, the activity component is still in the boot process, that is, its window has not yet been displayed, At this point, however, the Activitymanagerservice service checks whether a startup window needs to be displayed for the activity component being started. If necessary, the Activitymanagerservice service requests the Windowmanagerservice service to set up a startup window for the activity component being started (PS: And this startup window is the origin of screen).

1. activitystack.startactivitylocked

public class Activitystack {//set to False to disable the preview this is shown while a new activity/are being St
  Arted.

  Static Final Boolean Show_app_starting_preview = true; Private final void startactivitylocked (Activityrecord R, Boolean NewTask, Boolean doresume) {final int NH = mhistory.

    Size ();

    int addpos =-1;
    The place to new activity was in the top of stack, and so it was next to interact//with the user.
    if (Addpos < 0) {addpos = NH;

    }//Slot the activity into the history stack and proceed Mhistory.add (Addpos, R); if (NH > 0) {//We want to show the starting preview Windows if We are//switching to a new task, or N
      Ext activity ' s process are//not currently running.
      Boolean showstartingicon = Newtasks;
      Processrecord proc = R.app;
      if (proc = = null) {proc = MService.mProcessNames.get (R.processname, R.info.applicationinfo.uid); } if (proc = null | | proc.thread = = Null) {Showstartingicon = true;

 }


    }
  }
}

Not to be continued ... I hope you will continue to pay attention.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.