I am doing web development, recently in learning Android.
During the weekend, I want to write a delay into the main interface of the function, mainly used in handler and runnable, the code is as follows:
package com.zx.app;import android.app.Activity;import android.content.Intent;import android.os.bundle;import android.os.handler;import android.view.view;import android.widget.button;public class startscreenactivity extends activity { Private final int splash_display_lenght = 3000; // 3 seconds start Interface delay private Button btn; @Override protected void oncreate (bundle savedinstancestate) { // todo auto-generated method stub super.oncreate ( savedinstancestate) setcontentview (R.layout.splash); btn = (Button) This.findviewbyid (r.id.enter); //Create a thread final runnable myrun = new runnable () { @Override public void run () { // todo auto-generated meThod stub intent intent = new intent (StartScreenActivity.this, mainactivity.class); startactivity (Intent); finish (); } }; final handler handler = new handler (); //uses the Handler object to start the thread on a timed run handler.postdelayed (myrun, splash_ Display_lenght) //Direct Click Skip lazy load into the main interface btn.setonclicklistener (New view.onclicklistener ( ) { @Override public void onclick (view v) { // todo auto-generated method stub // Remove the handler delay load inside the thread, there will be no execution two times handler.removecallbacks (Myrun); Intent intent = new intent (startscreenactivity.this, Mainactivity.class); &nBsp; startactivity (intent); finish (); } }); }}
In the writing of this code encountered in the main interface after jumping back to delay loading the page, and then come to Oschina to ask for help, after the issue of a lot of seniors to the generous answer, thank them.
Android delay into main interface and click button to enter main interface code