Now the app will generally have a welcome interface when the application starts, this kind of welcome interface usually has two kinds of situations, one is used to detect the network state in the background when the application starts, or load the network data and so on some time-consuming operation, for instance QQ, micro-letter. There is also a way to start their own brand logo, generally for the logo, such as Taobao. Today I'm going to do both of these effects by simply coding.
1, in the background load network data, run some time-consuming tasks, the code is as follows:
Welcomeactivity.java File Code
public class Welcomeactivity extends activity {
@Override
protected void onCreate (Bundle savedinstancestate) { C3/>super.oncreate (savedinstancestate);
Requestwindowfeature (window.feature_no_title);
Setcontentview (r.layout.activity_welcome);
New Thread (New Runnable () {
@Override public
void Run () {
//Here runs the time-consuming task
Runonuithread (New Runnable () c11/> @Override public
void Run () {
Intent Intent = new Intent (welcomeactivity.this, mainactivity.class);
StartActivity (intent);
WelcomeActivity.this.finish ();}})
. Start ();
}
This will automatically disappear after the data load ends.
2, the page will stay fixed time
The Welcomeactivity.java file code is as follows:
public class Welcomeactivity extends activity {
@Override
protected void onCreate (Bundle savedinstancestate) { C3/>super.oncreate (savedinstancestate);
Requestwindowfeature (window.feature_no_title);
Setcontentview (r.layout.activity_welcome);
Handler Handler = new Handler ();
When the timer is over, jump to the main interface
handler.postdelayed (new Runnable () {
@Override public
void Run () {
Intent Intent = New Intent (Welcomeactivity.this, mainactivity.class);
StartActivity (intent);
WelcomeActivity.this.finish ();
}
, 3000);
}
The feature of this approach is that the Welcome page will stay at a fixed time, suitable for placing ads or branding icons.
Finally, don't forget to modify the startup page in the Androidmanifest.xml file.
<activity android:name= ". Welcomeactivity ">
<intent-filter>
<action android:name=" Android.intent.action.MAIN "/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</ Activity>
OK, the above is simply welcome to the production of the page ideas.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.