gpt4 book ai didi

java - 如何开始新 Activity 并等待一段时间再开始另一 Activity ?

转载 作者:行者123 更新时间:2023-12-02 12:49:56 25 4
gpt4 key购买 nike

下面的代码启动 Activity “welcome1”并执行 Thread() 然后启动另一个名为“gps”的 Activity 但是当它执行正在运行的 gps Activity 而不运行欢迎 Activity 时

如何启动welcome1并等待一段时间然后启动 Activity GPS

代码

public class welcome1 extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()
.penaltyLog().build());
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome1);

final TextView welcome = (TextView) findViewById(R.id.textView7);
final TextView person = (TextView) findViewById(R.id.textView9);
final Intent v = getIntent();
final String abt = v.getStringExtra("frist_name");
Runnable myRun=new Runnable() {
@Override
public void run() {
for (int s=0;s<2;s++){
final int finalI =s;
runOnUiThread(new Runnable() {
@Override
public void run() {
if (finalI==0)
{
welcome.setText(welcome2);
person.setText(abt);
}
if (finalI==1)
welcome.setText(steps);
}
});
synchronized (this) {
try {
wait(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
};

Thread T=new Thread(myRun);
T.start();
String number = v.getStringExtra("mobile_number");
String pwd = v.getStringExtra("pass");

Intent d = new Intent(getBaseContext(),gps.class);
d.putExtra("mobile_number",number);
d.putExtra("pass", pwd);

startActivity(d);

}

最佳答案

您尝试过使用处理程序吗?

只需创建一个 Runnable 来启动下一个 Activity 并像这样运行:

new Handler().postDelayed(yourRunnable,timeinmillis)

关于java - 如何开始新 Activity 并等待一段时间再开始另一 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44635005/

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