fatal exception in android Timer

前端 未结 4 1624
旧时难觅i
旧时难觅i 2021-01-28 06:27

in my android application i\'m using Timer schedule.but getting Timer-0 fatal exception as below.how can i remove it.i have also mentioned code below -

01-28 13:         


        
4条回答
  •  甜味超标
    2021-01-28 07:01

    It is very simple, you are scheduling the Timer but not cancelling it never. So Task scheduled will be in the queue and wait for its turn. By that time it should get executed your Activity might not be in the foreground and it is unable to find the views. So it is throwing the Fatal Exception. Inorder, to get rid of the above issue, you need to cancel the tasks whenever you are going from that particular activity by calling myTimer.cancel().

    Or else

    Use the Handler class.

提交回复
热议问题