我不确定,是什么阻止了这项工作。我有代码设置导致3秒的时间延迟,但视图不工作,它保持黑色,然后3秒后切换到下一个屏幕。我想,我正在做时间延迟,并且在Android中没有调用某些内容来显示布局......
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
start = System.currentTimeMillis();
setContentView(R.layout.team);
}
protected void onStart()
{
super.onStart();
while(game)
{
now = System.currentTimeMillis();
if (now - start >= 5000)
{
game = false;
Intent about = new Intent(this, SplashScreen.class);
startActivity(about);
}
}
}
答案 0 :(得分:4)
我相信您希望实现一个延迟几秒钟的屏幕,然后启动您的主应用程序。就像主应用程序启动之前的启动画面一样?
然后这会对你有所帮助!
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** set time to splash out */
final int welcomeScreenDisplay = 4000;
/** create a thread to show splash up to splash time */
Thread welcomeThread = new Thread() {
int wait = 0;
@Override
public void run() {
try {
super.run();
/**
* use while to get the splash time. Use sleep() to increase
* the wait variable for every 100L.
*/
while (wait < welcomeScreenDisplay) {
sleep(100);
wait += 100;
}
} catch (Exception e) {
System.out.println("EXc=" + e);
} finally {
/**
* Called after splash times up. Do some action after splash
* times up. Here we moved to another main activity class
*/
startActivity(new Intent(CurrentActivity.this, NextActivity.class));
finish();
}
}
};
welcomeThread.start();
}
这是4秒延迟的屏幕。
答案 1 :(得分:0)
您应该使用Timer类来启动新活动。