Mobile phone Audio and Video 1 -- SplashActivity, 1 -- splashactivity

Source: Internet
Author: User

Mobile phone Audio and Video 1 -- SplashActivity, 1 -- splashactivity

/*** 1. set the started Activity to singleton mode */public class SplashActivity extends Activity {/*** whether the home page has been started */private boolean 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. postDe Layed (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 the home page */private void startMainActivity () {if (! IsStartMain) {isStartMain = true; Intent intent = new Intent (this, MainActivity. class); startActivity (intent); finish (); // close the current page }}@ Override protected void onDestroy () {// isStartMain = true; handler. removeCallbacksAndMessages (null); // remove all the reconciliation messages in the message queue from super. onDestroy () ;}@ Override public boolean onTouchEvent (MotionEvent event) {startMainActivity (); return super. onTouchEvent (event );}}

1. The thread where the Handler is located is new and the Runnable is executed.

 

2. There is a bug where the Activity is started multiple times. How can this problem be solved?

Method 1. Set the Activity to start to be a singleton only.
In the function list file android: launchMode = "singleTask"
Method 2. control from the source and execute the Code only once

Private boolean isStartMain = false;/*** jump to the homepage and close the current page */private void startMainActivity () {if (! IsStartMain) {isStartMain = true; Intent intent = new Intent (this, MainActivity. class); startActivity (intent); // close the current page finish ();}}

  

 

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.