-1

嗨,我是 Android 的新手,请帮帮我,我正在尝试使用以下代码为我的启动画面设置时间,但应用程序没有安装并返回 NULL。我使用的是安卓 4.1.2

public class SplashActivity extends Activity {

    //how long until we go to the next activity
    protected boolean _active = true;
    protected int _splashTime = 5000;

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

        // thread for displaying the SplashScreen
        Thread splashTread = new Thread() {
                @SuppressWarnings("deprecation")
                @Override
                public void run() {
                    try {
                        int waited = 0;
                        while(_active && (waited < _splashTime)) {
                            sleep(100);
                            if(_active) {
                                waited += 100;
                            }
                        }
                    } catch(InterruptedException e) {
                        // do nothing
                    } finally {

                        stop();
                    }
                }
            };
            splashTread.start();
        }
    }
4

1 回答 1

0

您甚至在活动可见之前尝试显示您的启动屏幕。注意:活动仅在 onCreate() 完成后可见。

于 2012-11-06T19:15:09.483 回答