【问题标题】:Why can't I view the splash screen?为什么我看不到启动画面?
【发布时间】:2012-04-29 17:56:57
【问题描述】:

我有下面的代码,它会创建一个启动画面。当我启动我的应用程序时,我看不到启动屏幕,而是直接看到第一个活动:

public class splash extends Activity {
    private static final int STOPSPLASH = 0;

    //time in milliseconds
    private static final long SPLASHTIME = 13000;

    private ImageView splash;

    //handler for splash screen
    private Handler splashHandler = new Handler() {
        /* (non-Javadoc)
         * @see android.os.Handler#handleMessage(android.os.Message)
         */
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case STOPSPLASH:
                    //remove SplashScreen from view
                    splash.setVisibility(View.GONE);
                    break;
            }
            super.handleMessage(msg);
        }
    };  

    /** Called when the activity is first created. */
    @Override
        public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        setContentView(R.layout.main);        

        Intent intent = new Intent(this, prima.class);

        splash = (ImageView) findViewById(R.id.imageView1);

        Message msg = new Message();
        msg.what = STOPSPLASH;       

        splashHandler.sendMessageDelayed(msg, SPLASHTIME);        

        startActivity(intent);  
    }
}

【问题讨论】:

    标签: android android-layout android-intent splash-screen


    【解决方案1】:

    您必须从您的处理程序中执行startActivity()。直接做就直接切换到下一个活动了。

    public class splash extends Activity {
        private static final int STOPSPLASH = 0;
        // time in milliseconds
        private static final long SPLASHTIME = 13000;
        private Intent nextActivity;
    
        // handler for splash screen
        private Handler splashHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case STOPSPLASH:
                        // start next Activity
                        startActivity(nextActivity);
                        break;
                }
            }
        };
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            setContentView(R.layout.main);
            nextActivity = new Intent(this, prima.class);
            splashHandler.sendEmptyMessageDelayed(STOPSPLASH, SPLASHTIME);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-19
      相关资源
      最近更新 更多