0

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)+"");
Rob Avery IV
  • 3,562
  • 10
  • 48
  • 72
chris
  • 85
  • 2
  • 11

2 Answers2

0

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

Droidman
  • 11,485
  • 17
  • 93
  • 141
  • Moreover, assuming that it did persist through said "Task Killer" it would crash on the next tick as it has references to UI elements that were destroyed when the activity was forcibly closed. – Machinarius Jan 25 '13 at 16:12
  • That makes a lot of sense. I was just curious. Thank you for your input. Maybe somewhere along the line, someone will come across this and it will answer their question. – chris Jan 25 '13 at 16:25
0

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

Lieuwe
  • 1,734
  • 2
  • 27
  • 41
  • Hmm. I never thought of that. Can you expand upon it? – chris Jan 25 '13 at 16:25
  • That depends on what you want. You could for instance make a timer service where your apps can register a timer event and when the event happens the service will do a call back - perhaps via a broadcast or maybe by sending an intent. You could even have it restart your app if it isn't running. – Lieuwe Jan 25 '13 at 16:33
  • interesting. I'll mess around with it and see what happens. I never considered this. – chris Jan 25 '13 at 16:41