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