gpt4 book ai didi

View 之间的Android时间延迟

转载 作者:搜寻专家 更新时间:2023-11-01 08:14:07 24 4
gpt4 key购买 nike

我不确定,是什么阻止了它的工作。我的代码设置导致 3 秒的时间延迟,但 View 不工作,它保持黑色,然后在 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);
}
}
}

最佳答案

我相信你想实现一个延迟几秒的屏幕,然后启动你的主应用程序。就像主应用程序启动前的启动画面一样吗?

那么这对你有帮助!

 /** 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 秒的屏幕。

关于 View 之间的Android时间延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6466388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com