Android delay into main interface and click button to enter main interface code

Source: Internet
Author: User

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

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.