您好我是Android的新手请帮帮我,我正在尝试使用以下代码为我的Splash屏幕设置时间但是应用程序没有安装并返回NULL。我正在使用Android 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();
}
}
答案 0 :(得分:0)
即使在活动可见之前,您也试图显示启动画面。 注意:只有在onCreate()完成后,活动才可见。