Countdown timer stops running in background

雨燕双飞 提交于 2019-12-08 13:42:43

问题


I have implemented a countdown timer in an application of mine. It runs in the background fine and dandy, but when i use advanced task killer, it stops the timer and the only way to restart it is to open the application again. Is there anyway to have the timer persist, even if I use something like advanced task killer?

Code:

    TextView tv;
    final MyCounter timer = new MyCounter(10000,1000);

    tv  = (TextView)findViewById(R.id.healthtext);
    tv.setText("10"); 
    timer.start();
}

public class MyCounter extends CountDownTimer{

    public MyCounter(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onFinish() {
        Toast.makeText(getApplicationContext(), "death", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onTick(long millisUntilFinished) {
        tv.setText((millisUntilFinished/1000)+"");

回答1:


as far as I know - nope, since task killers destroy your app's process causing any running threads to exit




回答2:


Not while the timer is part of your application. You can of course make a timer that is not part of the application.



来源:https://stackoverflow.com/questions/14525533/countdown-timer-stops-running-in-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!