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.