Welcome to Android Development

Source: Internet
Author: User

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.

 

 

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.