相关疑难解决方法(0)

尝试安排计时器时发生IllegalStateException

从cancel方法的文档中:

(松散地说,如果此方法阻止执行一个或多个计划的执行,则返回true。)

当我执行此代码时:

private Timer timer = null;
private TimerTask runnable = new TimerTask() {
    @Override
    public void run() {
        Log.e("DEBUG", "Scheduled task tick");
        if(!looper){
            Looper.prepare();
            looper = true;
        }
        VolleyConnect vc = new VolleyConnect();
        vc.connect(ErrorListActivity.this);
    }
};

@Override
public void onWindowFocusChanged(boolean focus){
    if(!focus){
        kill();
    }else{
        start();
    }
    Log.e("DEBUG", "FOCUS " + focus);
}

public void start(){
    if(timer == null){
        timer = new Timer();
        //180000 ms = 3 minutes
        timer.scheduleAtFixedRate(runnable, 0L, 180000L);<--- This line is the one that triggers the …
Run Code Online (Sandbox Code Playgroud)

java android

-3
推荐指数
1
解决办法
806
查看次数

标签 统计

android ×1

java ×1