Can't stop/restart AsyncTask

后端 未结 3 1486
执笔经年
执笔经年 2021-01-24 01:36

Please help. I can restart the AsyncTask. App crashes every time, when second call to updatePoi().

Here is my code:

  1. I\'m checking status of task and set

相关标签:
3条回答
  • 2021-01-24 02:03

    try

    return null;
    

    final code

    @Override
    protected Void doInBackground(Void... voids) {
        Application app = (Application)getApplication();
        Log.d(TAG, "exits count = " + app.getExits().size());
    
        GeoPoint pointToNavigate = null;
    
        for (Exit exit : app.getExits()) {
    
            for (Poi poi : exit.getPoi()) {
                if (isCancelled()){
                    return null;
                }
                //some code here
            }
        }
    
        //small code here
        return null;
    }
    
    0 讨论(0)
  • 2021-01-24 02:05

    An AsyncTask instance can only be called once. To make a second call, you need to create a new instance.

    0 讨论(0)
  • 2021-01-24 02:09

    You can't restart a task. Each task object may only be executed once:

    The task can be executed only once (an exception will be thrown if a second execution is attempted.)

    So create a new object each time you execute it, don't use the same object.

    0 讨论(0)
提交回复
热议问题