Mobile video 1--splashactivity

Source: Internet
Author: User

/** * 1. Set the activity to be activated as a singleton mode */public class Splashactivity extends Activity {/** * has started the main Page */private bool    Ean isstartmain = false;    private static final String TAG = SplashActivity.class.getSimpleName ();    Private Handler Handler = new Handler ();        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_splash);                Handler.postdelayed (New Runnable () {@Override public void run () {//This method is executed in the main thread                LOG.E (TAG, "name of the current thread:" + thread.currentthread (). GetName ());            Startmainactivity ();    }}, 3000);            }/** * Start Main Page */private void startmainactivity () {if (!isstartmain) {Isstartmain = true;            Intent Intent = new Intent (this,mainactivity.class);            StartActivity (Intent); Finish ();//close Current page}} @Override protected void OnDestroy () {//Isstartmain = true;    Handler.removecallbacksandmessages (null);//Remove All back-and-reconciliation messages from the message Queue Super.ondestroy ();        } @Override public boolean ontouchevent (Motionevent event) {startmainactivity ();    Return Super.ontouchevent (event);  }}

1.Handler on which thread new,runnable is executing on which thread

2. There is a bug that started multiple activity, how to solve?

Method ①. The activity set to start can only be a singleton.
In the feature manifest file android:launchmode= "Singletask"
Method ②. Control from the source, execute code only once

Private Boolean Isstartmain = false;/** * Jumps to the main page and closes the current page off */private void startmainactivity () {if (!isstartmain) { Isstartmain = true;intent Intent = new Intent (this,mainactivity.class); startactivity (Intent);//close current page finish ();}}

  

Mobile video 1--splashactivity

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.