1

I start a timer in activity1. And in the timer task, I run some code continuously for a long time. Then I sometimes need to start activity2 like below.

Intent intent = new Intent();
intent.setClass(Tomato.this, History.class);
startActivity(intent);      

But then error occurs:

FATAL EXCEPTION: timer-1

Could anyone help?

Further:

I tested again, and found that this error didn't occur every time. Now I cannot even repeat it. Thanks for all of you!

Al Fahad
  • 2,378
  • 5
  • 28
  • 37
Tom Xue
  • 3,169
  • 7
  • 40
  • 77

1 Answers1

0

"I run some code continuously for a long time"

This is usually when you decide that this code should run in a service. Check out the Service SDK documentation and you'll get an example of local Service.

If the timer is just something you need to access accross activities, you could implement a singleton that will hold one instance of it.

Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124