/** * 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