【问题标题】:Android: Splash Screen re-opens app to second page even if app is quit during splash screenAndroid:即使在启动画面期间退出应用程序,启动画面也会将应用程序重新打开到第二页
【发布时间】:2012-03-20 17:07:49
【问题描述】:

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

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

问题是,如果用户在启动画面期间点击主页按钮或后退按钮退出应用程序,那么应用程序将在启动画面完成后重新打开到第二个屏幕,如果用户这样做了没有出口。

我的代码与教程的代码差不多。有什么帮助吗?

谢谢

【问题讨论】:

  • 错误的方式是它们妨碍了无缝的用户体验,并且通常在功能上毫无意义,而且大多数时候只是一个计时器等待(并且让用户也等待)

标签: android splash-screen


【解决方案1】:

我已经修改了代码以更好地利用生命周期方法。喜欢改变它。 :)

   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();
            }

        }
    }

我的观点是,启动画面的使用并不频繁,但可能需要。如果您在屏幕后面做繁重的工作(例如游戏)。

【讨论】:

  • 非常感谢。闪屏到目前为止是没用的(我理解为什么人们不喜欢它们),但我拥有这个的理由是 1. 与我一起工作的人想要它 2. 我可能需要时间从服务器(大量图像,因此可能需要一些时间)。另外,我是应用程序开发的新手,我认为实现一个并知道如何实现会很有趣
  • 欢迎。如果数据很大,可能需要它。尽管在加载图像的情况下,请选择“延迟加载图像”,(Romain Guy,Android Shelves 等有一个非常好的示例),以便用户可以在加载图像时继续使用您的应用程序。
  • 感谢您的建议,我会调查一下。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-09-27
  • 2011-11-28
  • 2011-04-19
  • 1970-01-01
  • 2021-06-10
  • 1970-01-01
  • 2013-03-07
相关资源
最近更新 更多