Skip to content
Advertisement

Why does my Timer crashes my android activity when I stop it?

I’m trying to make a toggle button that can stop and replay a Timer, it worked just fine until I added a new method called “Set_BPM”. It starts and it stops correctly, it crashes when I try to start it again after I stopped it.

This is the class where I’m using the Timer:

JavaScript

And this is how I’m calling it:

JavaScript

There’s also this object on top of my Activity:

JavaScript

This is what Logcat says

Advertisement

Answer

Once you cancel() a Timer, you cannot schedule more tasks with it. Quoting the documentation:

Once a timer has been terminated, its execution thread terminates gracefully, and no more tasks may be scheduled on it.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement