Small example of the Welcome interface for Android Development _android

Source: Internet
Author: User

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" &LT;/SPAN&GT; <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.

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.