我有两个活动:mainactivity6(父级)和tool1mode1(子级)
从父活动:
if (tool == 1) {
switch (mode) {
case 1:
intentTool1mode1.putExtra("Type", typekey);
intentTool1mode1.putExtra("Key", Key);
intentTool1mode1.putExtra("Tool", "Tool 1");
intentTool1mode1.putExtra("Mode", "Home");
Toast.makeText(MainActivity6.this, "Type: " + typekey + "\n" + "Key: " + Key + "\n" + "Tool: " + "1" + "\n" + "Mode: " + "Home" + "\n", Toast.LENGTH_LONG).show();
if(key_60.isChecked())
{
String number = "480000";
long val = Long.parseLong(number);
intentTool1mode1.putExtra("Time",val);
startActivityForResult(intentTool1mode1, 1);
}
if(key_90.isChecked())
{
String number = "720000";
long val = Long.parseLong(number);
intentTool1mode1.putExtra("Time",val);
startActivityForResult(intentTool1mode1, 1);
}
break;
这是儿童活动的一部分:
private long START_TIME_IN_MILLIS;
private long mTimeLeftInMillis = START_TIME_IN_MILLIS;
private CountDownTimer mCountDownTimer;
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Intent intent = getIntent();
START_TIME_IN_MILLIS = intent.getLongExtra("Time", 0);
newbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startTimer();
}
});
下面的代码表示我用于启动和更新子活动中计数器的两个函数:
private void startTimer()
{
mCountDownTimer = new CountDownTimer(mTimeLeftInMillis, 1000) {
@Override
public void onTick(long millisUntilFinished) {
mTimeLeftInMillis = millisUntilFinished;
updateCountDownText();
progress++;
pb.setProgress((int)progress*100/(480000/1000));
}
@Override
public void onFinish()
{
progress++;
pb.setProgress(100);
//Vibration
if (Build.VERSION.SDK_INT >= 26)
{
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(150, VibrationEffect.DEFAULT_AMPLITUDE));
Toast.makeText(com.example.ticwatch_1.tool1mode1.this,"Done",Toast.LENGTH_SHORT).show();
}
else
{
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createWaveform(new long[]{150}, new int[]{VibrationEffect.EFFECT_CLICK},-1));
}
}
}.start();
}
private void updateCountDownText()
{
//time in minutes and seconds
int minutes = (int)(mTimeLeftInMillis/1000)/60;
int seconds = (int)(mTimeLeftInMillis/1000)%60;
//formating the above to appear as String
String timeLeftFormatted = String.format("%02d:%02d",minutes,seconds);
timer.setText(timeLeftFormatted);
}
我想要的是从父活动获取值,并用我获取的值更新start\u time\u的值(以毫秒为单位)。所以我想让计时器运行8分钟,我去拿48万。我得到的是计数器是0,当我启动它,因为它已经完成,没有从8分钟或任何其他值开始。我不知道该怎么办,我累坏了。
暂无答案!
目前还没有任何答案,快来回答吧!