Unable to start the timer in a service in android

后端 未结 1 1657
你的背包
你的背包 2021-01-21 00:46

I dont know whats wrong going on... I am not able to start a timer in my service. Following the code

public class BkgService extends Service{

private Timer Ser         


        
相关标签:
1条回答
  • 2021-01-21 01:27

    From the Javadoc for Timer.cancel():

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

    From the Javadoc for Timer.scheduleAtFixedRate():

    Throws: IllegalStateException - if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated.

    The Timer is cancelled immediately: you need to create a new instance:

    private void StartServUpdateTask() {
    
        if(ServUpdTimer != null)
        {
            ServUpdTimer.cancel();
        }
        ServUpdTimer = new Timer();
    
        ...
    }
    
    0 讨论(0)
提交回复
热议问题