将倒数计时器值传递给下一个 activity

Passing countdown timer value to next activity

我正在尝试将倒数计时器值作为文本视图传递给下一个 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 您可以在另一个视图中设置数据或对其进行任何操作:

    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.