How to switch between Android activity with a short black screen

Source: Internet
Author: User

Transferred from: http://www.cppblog.com/fwxjj/archive/2013/01/14/197259.html

By default, when Android applications start, there is a black screen period, because the first activity loads some data, such as initializing list data, sending requests to the server for data, and so on. Similarly, use startactivity (inte ...

By default, when Android applications start, there is a black screen period, because the first activity loads some data, such as initializing list data, sending requests to the server for data, and so on. Similarly, when you use the StartActivity (intent) method to enter a new activity from an activity, a short black screen appears in the process. The existence of this problem is determined by the Android application framework, but it does affect the user experience. Here's how to solve this black screen problem!

First step: Customizing Theme (Theme)

Add the theme for the custom activity in Your_project/res/values/styles.xml as follows:

View PlainCopy
    1. <?xml version= "1.0" encoding= "Utf-8"?>
    2. <resources>
    3. <!--activity Topics--
    4. <style name= "Activitytheme" parent= "@android: Style/theme" >
    5. <item name= "Android:windowistranslucent" >true</item>
    6. </style>
    7. </resources>

where <item name= "android:windowistranslucent" >true</item> means that setting the target activity (the activity to start) is transparent. It's easy to understand, two activity,a and b; start B in A, because B is transparent and the background is still a, which solves this short black screen problem.

Step Two: Modify the manifest to apply the theme to the target activity

Once the theme is defined, it is time to bind the theme to the corresponding activity. This code is implemented primarily in manifest, with the following attributes added to the activity:

View PlainCopy
    1. <activity android:name= ". Activity. Placingorderstep1activity "
    2. Android:theme= "@style/activitytheme"/>

OK, to solve this problem, if you do not believe, try it!

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.