安卓:开机画面重新打开应用程序,即使应用程序是在启动画面退出第二页 [英] Android: Splash Screen re-opens app to second page even if app is quit during splash screen

查看:129
本文介绍了安卓:开机画面重新打开应用程序,即使应用程序是在启动画面退出第二页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我使用本教程中创建一个非常简单的启动画面:

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

的http:// P-XR .COM / Android的教程,如何对做-A-基本-闪屏/

现在的问题是,如果用户点击主页按钮或后退按钮退出启动画面持续时间内应用程序,然后应用程序将重新打开第二个屏幕后启动画面就已经完成,如果用户没有没有出口。

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.

我的code是pretty的多,该教程。任何帮助吗?

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

感谢

推荐答案

我已经修改了code利用的生命周期方法更好。喜欢改变它。 :)

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).

这篇关于安卓:开机画面重新打开应用程序,即使应用程序是在启动画面退出第二页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆