0
我的計時器代碼:Countdowntimer如何繼續在我的應用程序中按下後退按鈕時在後臺運行?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initializer();
fire.setOnClickListener(this);
}
private void initializer() {
minute = (EditText) findViewById(R.id.etMinute);
seconds = (EditText) findViewById(R.id.etSeconds);
fire = (Button) findViewById(R.id.bFireTimer);
Remain=(TextView)findViewById(R.id.tvRemain);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bFireTimer:
min=minute.getText().toString();
sec=seconds.getText().toString();
int MIN= Integer.parseInt(min);
int SEC=Integer.parseInt(sec);
long TIME= (MIN*60)+SEC;
timercount = new MyCount(TIME * 1000, 1000);
timercount.start();
break;
}
}
public class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
//some script here
}
@Override
public void onTick(long millisUntilFinished) {
//some script here
int remseconds=(int)millisUntilFinished/1000;
int remminuts=remseconds/60;
remseconds= remseconds%60;
remminuts= remminuts%60;
Remain.setText(String.format("%d : %02d" , remminuts,remseconds));
// Remain.setText(""+millisUntilFinished);
} }
當我給的分和秒輸入,並按下開火按鈕時,我從我的應用程序退出,則計時器不能繼續在後臺運行定時器將start.But。我想繼續運行計時器,當我退出我的應用程序,當我開始我的應用程序時,我看到正在運行的計時器..plz我需要幫助做到這一點.. 在此先感謝。