First you have to write good XML files, which is also the most important.
Then, add a thread to the activity and delay it for 2 seconds to jump to the main interface.
The activity thread code is as follows: (By the way, check if the network is open)
[Java]
Copy Code code 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{
Pop-up dialog lets users set up the network
Alertdialog.builder Builder = new Builder (this);
Builder.settitle ("Set up Network");
Builder.setmessage ("Network error please set up network");
Builder.setpositivebutton ("Set Up 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,compusassistmain.class);
StartActivity (Intent);
Finish ();
catch (Interruptedexception e) {
E.printstacktrace ();
}
}
}.start ();
}else{
Pop-up dialog lets users set up the network
Alertdialog.builder Builder = new Builder (this);
Builder.settitle ("Set up Network");
Builder.setmessage ("Network error please set up network");
Builder.setpositivebutton ("Set Up 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's Class isnetworkconnected ():
[Java]
Copy Code code as follows:
<span style= "White-space:pre" > </span>/**
* Determine if the system's 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 if the system's 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;
}
This completes a welcome interface, adding color to the application. And, of course, add the configuration to the manifest file.
[HTML]
Copy Code code 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>
This will open the application and start the first activity interface.