所以,我刚读到这个问题:如何制作启动画面? 但是,我不想添加固定延迟(如在最佳答案中),而是希望在 MainActivity(带有 MapFragment)加载时保持启动画面。
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
synchronized (this) {
try {
wait(3000);
System.out.println("Thread waited for 3 seconds");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
try {
t.start();
t.join();
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
我添加了 wait(3000) 行,因为我之前注意到该线程没有存活很长时间。但是,如果我让它等待更长时间,就会出现持续更长时间的黑屏。由于某种原因,SplashScreen 活动不会显示 ImageView。我应该怎么办?谢谢。