Android optimized launch page go to black screen to implement second boot _android

Source: Internet
Author: User

Objective

Remember before we wrote an article, based on Rxjava implementation of the cool Start page, however, when we click on the desktop icon to start the app, sometimes flash a black background, sometimes the black background time is still relatively long, ah, ugly dead, this How to pinch, other side, we will take a look at the Start Page optimization.

First, eliminate the start of the black screen

Click on the Desktop Launcher icon to start the app, the Flash black background actually appears before we see the first frame of the interface. Then we need to find a way to make this black background into a picture that users like to see or make it transparent. With a way of thinking is also rough, we have the following two kinds of programs:

Customizing the Welcomactivity Theme

To put it bluntly, the black screen that appears is set by the Android:windowbackground property to the background we want.

1. Define the following style in Style.xml

<style name= "Welcomestyle" parent= "Android:theme" >    
  <item name= "Android:windowbackground" >@ drawable/welcome_bg</item>  
  <item name= "Android:windownotitle" >true</item>  
</style >

Where WELCOME_BG can be the logo background of our app.

2. Configure welcomeactivity in manifest files

<activity      
   android:theme= "@style/welcomestyle" 
   android:name= ". Activity.welcomeactivity ">    
</activity>

Using Transparent Themes Android:Theme.Translucent.NoTitleBar.Fullscreen

The use of transparent theme, point icon on the desktop to wait for a little while, then the entire interface will be displayed all of a sudden, people mistakenly think that the desktop launcher rather than application (whining, mobile phone manufacturers say this pot I do not back). Do you think it's a little thoughtful? In fact, micro-letter is so used, you do not point to the micro-letter to try ~ ~

1. Define the following style in Style.xml

<style 
   name= "appwelcome" 
   parent= "Android:Theme.Translucent.NoTitleBar.Fullscreen" >
</ Style>

2. Configure welcomeactivity in manifest files

<activity      
   android:theme= "@style/appwelcome" 
   android:name= ". Activity.welcomeactivity ">    
</activity>

OK, so simple, now let's look at the effect of the second method:

Is it true that there is no black background flash? In fact, we can also optimize, so that starting faster, please continue to see.

Second, start optimization, let app seconds open

Optimize application

From the user click on the launcher icon to see the first frame of the interface to apply the START process, mainly through the following methods:

Main ()->application:attachbasecontext ()->oncreate ()->activity:oncreate ()->onstart ()->onResume ()

main->ActivityThis process is created through a series of framework layers that are not easy to optimize for what the system does automatically, but if we inherit application customize our own application, we can do the following optimizations:

1. Try not to put some business logic in the application;

2. Do not save application data in application in the form of static variables;

3. Do not put files, database operations in the application

Optimize startup page Activity

The startup page tries to avoid time-consuming operations such as network requests. A time-consuming operation that should be canceled in due course if a request network is used. For example, some times, when the user clicks on the launcher icon, but immediately wants to exit click the Return key, after a few seconds users are using other apps, suddenly jump to our app that the user experience is very bad. So you can cancel the time-consuming operation in the return event

@Override public 
void onbackpressed () { 
super.onbackpressed (); 
....                The time-consuming operation canceled here
}

Or you can rogue some, directly in the Start Page activity rewrite onKeyDown() method, first of all, to determine whether the user is pressed to return the key, if the words directly return true, so that the back of the key to return the implementation of the logic to prevent the user to return to the operation of the purpose to see the code

@Override Public 
boolean onKeyDown (int keycode, keyevent event) { 
   if (keycode = = keyevent.keycode_back) {
       return true; 
   } 
   Return Super.onkeydown (KeyCode, event); 
}

In this way, this article to the end of the content, we have better optimization skills welcome message Exchange Learning, I hope this article for everyone to develop Android help.

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.