The basics of Android development the way to create a startup interface splash screen _android

Source: Internet
Author: User

This example describes the Android Development Foundation's approach to creating the Startup Interface splash screen. Share to everyone for your reference. Specifically as follows:

Start Interface splash screen in the application is very common, often in the launch interface display product logo, company logo or developer information, if the application startup time is relatively long, then the start interface is a good thing, can let the user patiently wait for this boring time.

Android Apps Create a startup interface splash screen is very simple. For example, to create a project mysample, the main acitity is called Mysample, create another activity called SplashScreen, used to display the startup interface, resource file for Splash.xml. As for how to make the Splashsceen interface, this is not what this article is going to discuss, skip over.

The code for SplashScreen is as follows:

Package com.ctoof.android;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import android.view.MotionEvent;
 public class SplashScreen extends activity {protected Boolean _active = true;
 protected int _splashtime = 5000;
  @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
  Setcontentview (R.layout.splash);
     Thread splashtread = new Thread () {@Override public void run () {try {int waited = 0;
      while (_active && (waited < _splashtime)) {sleep (100);
      if (_active) {waited = 100;
     The catch (Interruptedexception e) {//Do nothing} finally {finish ();
     Start the main application startactivity (new Intent ("com.ctoof.android.MySample.MyApp"));
    Stop ();
  }
   }
  };
 Splashtread.start (); @Override public boolean ontouchevent (Motionevent event) {if (event.getaction () = = Motionevent.action_down) {_a
  Ctive = false;
}  return true;

 }
}

The

Then modifies the code in Androidmainfest.xml as follows:

 <?xml version= "1.0" encoding= "Utf-8"?> <manifest "xmlns:android=" Schemas.android.com/apk/res/android "package=" Com.ctoof.android "android:versioncode=" 1 "android:versionname=" 1.0 "> <application android:icon=" @drawable/icon "android:label=" @string/app_name "> <activity android:name= ". SplashScreen "android:label=" @string/app_name "> <intent-filter> <action android:name=" Android.inte Nt.action.MAIN "/> <category android:name= Android.intent.category.LAUNCHER"/> </intent-filter> & Lt;/activity> <activity android:name= ". MyApp "> <intent-filter> <action android:name=" com.ctoof.android. Mysample.myapp "/> <category android:name= Android.intent.category.DEFAULT"/> </intent-filter> & lt;/activity> </application> <uses-sdk android:minsdkversion= "4"/> </manifest> 

You are responsible for registering two activities here. Take the active activity responsible for managing the startup Interface splash screen as the main activity for the application, and then start the MyApp in SplashScreen.

I hope this article will help you with your Android program.

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.