Android timer timer stop and restart implementation code
This paper introduces the stop and restart implementation code of Android timer, which is shared with you as follows:
In July, I made a project to present an animation using custom controls. At that time, I used a timer to control the time, but there was always a problem when it stopped opening. I've been looking for a reasonable way to solve this problem, but I haven't found it. Recently, I finally found a reasonable way to solve this problem.
You must know how to query relevant information. Timer and TimerTask are cancelled by timer. Cancel() and mtimertask. Cancel(). However, you will report an error when you start timer again after you find that this hairstyle is cancelled
This problem is solved by using cancle(). After canceling the timer, you also need to clear the timer. A reasonable code should look like this:
After solving the key problems, here is my case code mainactivity.java:
XML part code:
String part code:
The above is my source code. If you have any questions, you can leave a message for discussion.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.