Fatal Spin-On-Suspend/Stuck on ThreadID

后端 未结 2 1482
天涯浪人
天涯浪人 2021-01-02 02:29

I\'m creating a custom calendar for an Android app. The way it works now is that it pulls events from an online MySQL database, transfers them into a JSONArray, and inputs t

2条回答
  •  感情败类
    2021-01-02 03:05

    I went about this a slightly different way:

    First I set a field in the AsyncTask class

    private boolean taskDone = false;
    

    Then, after the doInBackground code (or in postExecute):

    this.taskDone = true;
    

    Finally add a method to the AsyncTask:

    public boolean isTaskDone() {
        return taskDone;
    }
    

    Now you can use isTaskDone as the argument in the while loop:

    while (!isTaskDone()) {
    // wait for task
    }
    

    Just my way of doing it, I'm sure there are many more

提交回复
热议问题