代码之家  ›  专栏  ›  技术社区  ›  anon

喷溅屏有时才出现

  •  2
  • anon  · 技术社区  · 14 年前

    我定义了一个SplashScreen,方法如下:

    /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ExceptionHandler.register(this);
            setFullscreen();
            splashScreen();
        }
    
    private void splashScreen() {
    
            runOnUiThread(new Runnable() {
    
                @Override
                public void run() {
                    setContentView(R.layout.splashscreen);
                    splash = (ImageView) findViewById(R.id.splashscreenLayer);
                    startSplashTime = new Date();
                }
            });
    
            new LoadingThread().start(); 
        }
    
    private class LoadingThread extends Thread {
    
            @Override
            public void run() {
                checkNetwork();
            }
    
        }
    

    在checknetwork()方法的特定条件下,调用stopslash方法:

    public void stopSplash() {
            Message msg = new Message();
            msg.what = STOPSPLASH;
    
            Date endSplashTime = new Date();
            long time = endSplashTime.getTime() - startSplashTime.getTime();
            System.out.println("Time Splashscreen was displayed: " + time);
            if (time < SPLASH_MIN_TIME) {
                long delay = SPLASH_MIN_TIME - time;
                System.out.println("Delay Splashscreen for: " + delay);
                try {
                    Thread.sleep(delay);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                splashHandler.sendMessage(msg);
            } else {
                System.out.print("Show Splashscreen now");
                splashHandler.sendMessage(msg);
            }
        }
    private Handler splashHandler = new Handler() {
    
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case STOPSPLASH:
                        splash.setVisibility(View.GONE);
                    break;
                }
                super.handleMessage(msg);
            }
    
        };
    

    问题是,有时(可能是10个中的1个)如果我直接从Eclipse启动应用程序,splashscreen不会显示,而是显示一个黑屏。

    其他问题:如果我重新启动应用程序,例如在单击设备上的后退按钮后调用OnDestroy()之后,SplashScreen几乎不会显示。

    有什么提示吗?

    我的假设是:可以这样吗,加载线程的启动速度比可运行文件“快”,因此网络工作人员在设置SplashScreen之前就已经完成了?

    2 回复  |  直到 14 年前
        1
  •  0
  •   ZachM    14 年前

    您可以尝试在实现中使用CountDownTimer。在您的第一个活动中,启动一个倒数计时器,该计时器会每隔一段时间在onfinish()中检查一次同步布尔值finishedLoading(15秒或其他时间),同时在另一个线程中完成加载,该线程在完成后将finishedLoading设置为true。

        2
  •  0
  •   Nanda    14 年前

    可能在V=下一个活动开始之前,启动屏幕没有终止。只是个想法……