How to Implement the welcome Screen for common Android UI instances)

Source: Internet
Author: User

How to Implement the welcome Screen for common Android UI instances)

On the Android platform, after downloading an app, Splash Screen is the first thing that will pop up for the first time. This Splash Screen is not recommended in terms of Android design principles. Let's take a look at the general use of Splash Screen:

1. After the first installation, the pop-up screen of a simple APP can achieve the goal of brand marketing. The complicated APP is used to provide guidance for new users;

2. Update the version to describe the new features of the version;

Some people sneer at this kind of design, and others are eager to follow it. We will not discuss the advantages and disadvantages.

1. Simple Splash Screen

The implementation of this Splash Screen is simple. It is often used to display simple information such as the product Logo or version number. We only need to find a way to automatically jump to the main interface of the application after the WelcomeActivity runs for several seconds;

We only need to use a simple method:

// After 3 s, run the run method to start the main interface Activity new Handler (). postDelayed (new Runnable () {@ Override public void run () {Intent I = new Intent (SplashScreen. this, MainActivity. class); startActivity (I); // after the main Activity is started, destroy itself finish () ;}, 3000 );
2. Splash Screen involving complex operations

The so-called complex operation is often because such an application requires many background operations before entering the interface. The Splash Screen allows users to wait. The operations generally involve:

Obtain data from the network and store it to download images locally. Obtain and parse JSON/XML files and send data to the server for authentication ....

Generally, this is a time-consuming operation similar to online download, but you have to do the work before the application enters the main interface. According to different applications, the work is also different. Here we obtain an image remotely. after entering the welcome page, we start to download an image remotely. Then we enter the main interface, display the parsed data on the main interface;

Image address:: Create a SplashScreen layout: res/layout/splash_screen.xml

      
       
        
    
   
  

Layout Effect

Create MainActivity layout: res/layout/activity_main.xmlOnly used to display images obtained remotely
    
      
       
   
  

4. After SplashScreenActivity is completed, we use AsyncTask to obtain and parse data and pass the data to MainActivity through Intent,

Public class SplashScreenActivity extends Activity {private static final String url = http://www.jycoder.com/json/Image/1.jpg; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. splash_screen);/** simple Splash Screen implementation ** // ** after 3 s, run the run method to start the main interface Activity new Handler (). postDelayed (new Runnable () {@ Override public void run () {Intent I = new Intent (SplashScreen. this, MainActivity. class); startActivity (I); // after the main Activity is started, destroy itself finish () ;}, 3000); ** // execute the task in the background, input url new fetchdatatask(cmd.exe cute (url);} public class FetchDataTask extends AsyncTask
  
   
{// Call @ Override protected void onPreExecute () {super. onPreExecute ();} // executes the background task @ Override protected Bitmap doInBackground (String... strings) {Bitmap bitmap = null; try {// obtain the image HttpURLConnection connection = (HttpURLConnection) (new URL (strings [0]) through the input image address. openConnection (); InputStream is = connection. getInputStream (); bitmap = BitmapFactory. decodeStream (is);} catch (IOException e) {e. printStackTrace ();} return bitmap;} // call @ Override protected void onPostExecute (Bitmap result) {super. onPostExecute (result); // transmits the obtained data to MainActivity Intent = new intent (SplashScreenActivity. this, MainActivity. class); // note that when intent transmits an image, the image object size should not exceed 40 kb intent. putExtra (Image, result); startActivity (intent); // start MainActivity and destroy itself finish ();}}}
  

5. Complete MainActivity. Pay attention to how to accept the objects passed by Intent.

Public class MainActivity extends Activity {private ImageView imageView; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); imageView = (ImageView) findViewById (R. id. image); Intent intent = getIntent (); if (intent! = Null) {// note the way Intent transmits objects Bitmap bitmap = intent. getParcelableExtra (Image); imageView. setImageBitmap (bitmap );}}}

6. Remember to add the Internet permission to Manifest. xml and set SplashScreenActivity to start Activity.


  
      
                           
                                    
                 
     
                        
   
  

I encountered an error when I used an image stored remotely for the first time and encountered a very interesting problem:

Later I found this error because the size of the image cannot exceed 40 kb when I use Intent. Remember

Effect after completion:

Summary:

The above examples are very simple, but the idea of Splash Screen is basically nothing more than these, I hope it will help you.

Pay attention to the following public platforms ~~~ O (∩) O Haha ~

 

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.