安卓系统。即使在闪屏期间退出应用,闪屏也会重新打开应用到第二页[英] Android: Splash Screen re-opens app to second page even if app is quit during splash screen

本文是小编为大家收集整理的关于安卓系统。即使在闪屏期间退出应用,闪屏也会重新打开应用到第二页的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

好的,所以我使用本教程创建了一个非常简单的飞溅屏幕:

http://p-xr .com/android-tutorial-to-make-a-basic-splash-screen/

问题是,如果用户在飞溅屏幕持续时间期间击中主页按钮或返回按钮以退出应用程序,那么如果用户执行了在飞溅屏幕之后将重新打开到第二屏幕没有退出.

我的代码几乎是教程的代码.任何帮助?

感谢

推荐答案

我已修改代码以更好地利用生命周期方法.享受改变它. :)

   public class SplashScreen extends Activity {

        protected int _splashTime = 5000; 

        private Thread splashTread;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);


            final SplashScreen sPlashScreen = this; 

            // thread for displaying the SplashScreen
            splashTread = new Thread() {
                @Override
                public void run() {
                    try {                   
                        synchronized(this){
                            wait(_splashTime);
                        }

                    } catch(InterruptedException e) {} 
                    finally {

                        if(!isFinishing()) // This pretty useful boolean val tells if 
 //user has pressed the back button. very useful.
                        {Intent i = new Intent(SplashScreen.this, Main.class);

                        startActivity(i);
                         finish();
                         }


                        stop();
                    }
                }
            };

            splashTread.start();
        }
        @Override
        public boolean onTouchEvent(MotionEvent event) {


            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                Toast.makeText(this,"exec---",Toast.LENGTH_LONG).show();
                synchronized(splashTread){
                    splashTread.notifyAll();
                }
            }
            return true;
        }
        @Override
        protected void onPause() {

            super.onPause();

            if(splashTread.getState()==Thread.State.TIMED_WAITING){
                //Thread is still waiting and Activity is paused. Means user has pressed Home. Bail out
                finish();
            }

        }
    }

我的观点是使用飞溅屏幕不频繁,但可能需要.如果你在屏幕后面做了繁重的工作(如游戏).

本文地址:https://www.itbaoku.cn/post/102643.html

问题描述

Ok, so i created a very simple splash screen using this tutorial:

http://p-xr.com/android-tutorial-how-to-make-a-basic-splash-screen/

The problem is that if the user hits the home button or the back button to exit the app during the splash screens duration then the app will re-open to the second screen after the splash screen would have been done if the user did no exit.

My code is pretty much that of the tutorial. any help?

Thanks

推荐答案

I have modified the code to make use of the lifecycle methods better. enjoyed changing it. :)

   public class SplashScreen extends Activity {

        protected int _splashTime = 5000; 

        private Thread splashTread;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);


            final SplashScreen sPlashScreen = this; 

            // thread for displaying the SplashScreen
            splashTread = new Thread() {
                @Override
                public void run() {
                    try {                   
                        synchronized(this){
                            wait(_splashTime);
                        }

                    } catch(InterruptedException e) {} 
                    finally {

                        if(!isFinishing()) // This pretty useful boolean val tells if 
 //user has pressed the back button. very useful.
                        {Intent i = new Intent(SplashScreen.this, Main.class);

                        startActivity(i);
                         finish();
                         }


                        stop();
                    }
                }
            };

            splashTread.start();
        }
        @Override
        public boolean onTouchEvent(MotionEvent event) {


            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                Toast.makeText(this,"exec---",Toast.LENGTH_LONG).show();
                synchronized(splashTread){
                    splashTread.notifyAll();
                }
            }
            return true;
        }
        @Override
        protected void onPause() {

            super.onPause();

            if(splashTread.getState()==Thread.State.TIMED_WAITING){
                //Thread is still waiting and Activity is paused. Means user has pressed Home. Bail out
                finish();
            }

        }
    }

My point of view is that the use of Splash Screen is not frequent but maybe needed. If you are doing heavy work behind the screen( such as games).