IndexOutOfBound Exception throwing Android

后端 未结 2 756
逝去的感伤
逝去的感伤 2021-01-28 09:52

i have make one android application in that data is coming from server so it\'s time consuming process so i have created one progress dialog box..

below is my code

相关标签:
2条回答
  • 2021-01-28 10:15

    You are starting the asynctask every time you show your activity. So, you should cancel the task when exiting (AsyncTask.cancel(true)), or check if it is still running in the onResume method.

    0 讨论(0)
  • 2021-01-28 10:41

    In the cases where you get the error onResume() gets called again, starting a new AsyncTask. Now you have multiple AsyncTask simultanously accessing and altering the size of nearDeals.results (you call remove on it). When one asyncTask removes an item from the list, the second asyncTask may run into the ArrayIndexOutOfBounds since the list size has changed.

    EDIT: It's actually not the removal of an item, but that you set a new instance of the list in googlePlaces.search and this list may have a different size than the one used by the old asynctask.

    Solution: call cancel on your running async tasks in onPause (or in onResume before starting the new task)

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