First, you must write the XML file, which is also the most important.
Then, add a thread to the activity with a latency of 2 seconds to jump to the main interface.
Thread in ActivityCodeAs follows: (check whether the network is enabled by the way)
@ Overrideprotected void onstart () {super. onstart (); If ( Isnetworkconnected () ) {New thread () {@ overridepublic void run () {try {thread. Sleep (2000); intent = new intent ( Splashactivity. This , Compusdomainmain. Class ); Startactivity (intent); finish ();} catch (interruptedexception e) {e. printstacktrace ();}}}. start ();} else {// dialog box that allows you to set the network alertdialog. builder = new Builder (this); builder. settitle ("set network"); builder. setmessage ("network error, SET network"); builder. setpositivebutton ("set network", new onclicklistener () {public void onclick (dialoginterface dialog, int which) {intent = new intent (); intent. setclassname ( "Com. Android. Settings" , "Com. Android. settings. wirelesssettings" ); Startactivity (intent) ;}}); builder. setnegativebutton ("cancel", new onclicklistener () {public void onclick (dialoginterface dialog, int which) {finish () ;}}); builder. create (). show ();}}
Check the network type isnetworkconnected ():
/*** Determine whether the system network is available * @ return */private Boolean isnetworkconnected () {connectivitymanager CM = (connectivitymanager) getsystemservice (connectivity_service) network; info = cm. getactivenetworkinfo (); If (info! = NULL & info. isconnected () {return true;} else {return false ;}
In this way, a welcome interface is completed to add colors to your applications. Add the configuration in the manifest file.
<Activity Android: Name = "com. yan. compusassist. splashactivity "Android: Label =" @ string/application_name "> <intent-filter> <action Android: Name =" android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity>
In this way, the application is opened and the first activity interface is started.