Android countdown timer not working if i change va

2019-08-20 12:03发布

I am trying to make a program that you enter a number with numberpicker on the first activity and on the second activity there is a countdown timer that uses the number you entered on the first activity to countdown from in minutes(if you enter 10 it countdown 10 minutes).

public class timer_2 extends AppCompatActivity {
ImageButton imageButton3;
private TextView timer_2_up;
private TextView timer_2_down;
private CountDownTimer timer_2_up_countdowntimer;
private CountDownTimer timer_2_down_countdowntimer;
private boolean timer_2_up_running;
private boolean timer_2_down_running;
private long starttime;
private long starttimedown = starttime*60000;
private long starttimeup = starttime*60000;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_timer_2);
    timer_2_up = findViewById(R.id.timer_2_up);
    timer_2_down = findViewById(R.id.timer_2_down);
    imageButton3 = (ImageButton)findViewById(R.id.imageButton3);
    Bundle timer2extras = getIntent().getExtras();
    String timer2string = timer2extras.getString("timer2string");
    starttime = Integer.parseInt(timer2string);
    imageButton3.setOnClickListener(new View.OnClickListener() {
      //....                  

If i remove starttime*60000(9th row) both on startimeup and starttimedown and replace with a number (for example 600000) it works fine but with starttime it just shows 00:00.Please help me.

1条回答
混吃等死
2楼-- · 2019-08-20 12:42

Just declare starttimeup and starttime down in starting and initialise them after you get starttime value from 1st activity like:

long starttimeup;
long starttimedown;

And in onCreate:

starttime = Integer.parseInt(timer2string);
starttimeup = starttime*60000;
starttimedown = starttime*60000;
查看更多
登录 后发表回答