A small example of the welcome page for 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.

The thread code in the activity is as follows: (check whether the network is enabled by the way)

[Java]

Copy codeThe Code is as follows: @ Override
Protected void onStart (){
Super. onStart ();
If (<SPAN style = "COLOR: # ff0000"> isNetworkConnected () </SPAN> ){
New Thread (){
@ Override
Public void run (){
Try {
Thread. sleep (2000 );
Intent intent = new Intent (<SPAN style = "COLOR: # ff0000"> SplashActivity. this </SPAN>, <SPAN style = "COLOR: # ff0000"> CompusAssistMain. class </SPAN> );
StartActivity (intent );
Finish ();
} Catch (InterruptedException e ){
E. printStackTrace ();
}

}
}. Start ();
} Else {
// Dialog box asking users to set the network
AlertDialog. Builder builder = new Builder (this );
Builder. setTitle ("set network ");
Builder. setMessage ("set network error ");
Builder. setPositiveButton ("set network", new OnClickListener (){
Public void onClick (DialogInterface dialog, int which ){
Intent intent = new Intent ();
Intent. setClassName (<SPAN style = "COLOR: # ff6666"> "com. android. settings "</SPAN>, <SPAN style =" COLOR: # ff6666 ">" com. android. settings. wirelessSettings "</SPAN> );
StartActivity (intent );
}
});
Builder. setNegativeButton ("cancel", new OnClickListener (){

Public void onClick (DialogInterface dialog, int which ){
Finish ();
}
});
Builder. create (). show ();
}
}

@ Override
Protected void onStart (){
Super. onStart ();
If (isNetworkConnected ()){
New Thread (){
@ Override
Public void run (){
Try {
Thread. sleep (2000 );
Intent intent = new Intent (SplashActivity. this, compusdomainmain. class );
StartActivity (intent );
Finish ();
} Catch (InterruptedException e ){
E. printStackTrace ();
}

}
}. Start ();
} Else {
// Dialog box asking users to set the network
AlertDialog. Builder builder = new Builder (this );
Builder. setTitle ("set network ");
Builder. setMessage ("set network error ");
Builder. setPositiveButton ("set network", new OnClickListener (){
Public void onClick (DialogInterface dialog, int which ){
Intent 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 Class isNetWorkConnected ():

[Java]Copy codeThe Code is as follows: <SPAN style = "WHITE-SPACE: pre"> </SPAN> /**
* Determine whether the system network is available
* @ Return
*/
Private boolean isNetworkConnected (){
ConnectivityManager cm = (ConnectivityManager) getSystemService (CONNECTIVITY_SERVICE );
NetworkInfo info = cm. getActiveNetworkInfo ();
If (info! = Null & info. isConnected ()){
Return true;
} Else {
Return false;
}

/**
* Determine whether the system network is available
* @ Return
*/
Private boolean isNetworkConnected (){
ConnectivityManager cm = (ConnectivityManager) getSystemService (CONNECTIVITY_SERVICE );
NetworkInfo 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.
[Html]Copy codeThe Code is as follows: <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>

<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.