gpt4 book ai didi

java - 将倒数计时器值传递给下一个 Activity

转载 作者:行者123 更新时间:2023-12-01 17:20:22 24 4
gpt4 key购买 nike

我正在尝试将倒数计时器值作为 TextView 传递到下一个 Activity ,但我不知道如何,我需要使用intent.putextra()吗?这是我的代码:

    countDownTimer = new CountDownTimer(5000, 1000) {
@SuppressLint("DefaultLocale")
public void onTick(long millisUntilFinished) {
timpRamas.setText(String.format("%d:%d",
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished),
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))));
}
public void onFinish() {
Intent intent = new Intent(c1_1.this,TimpExpirat.class);
startActivity(intent);
finish();
}
}.start();

最佳答案

您必须将textView的数据传递给下一个 Activity ,并且在下一个 Activity 中您可以在另一个 View 中设置数据或对其执行任何操作:

    public void onFinish() {
Intent intent = new Intent(c1_1.this,TimpExpirat.class);
intent.putExtra("data" , timpRamas.getText().toString());
startActivity(intent);
finish();
}

在 TimpExpirat Activity 中:

//get the data in onCreate()

Intent intent = getIntent();
String time = intent.getStringExtra("data");

//time now has the time that was last set on your textview, you can set it
//to a new textview or do whatever with it.

关于java - 将倒数计时器值传递给下一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61304878/

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