Hello.
I use the official VK SDK and I want to get a list of VK users, starting with a specific id and ending with some number. In the documentation I did not find anything about the multiple values of the parameters and decided to do it stupidly with a while . For example, get 20 users.
do{ VKRequest request = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS, "photo_50", VKApiConst.USER_ID, String.valueOf(id))); request.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); VKList<VKApiUserFull> vkList = (VKList<VKApiUserFull>) response.parsedModel; for (VKApiUserFull userFull : vkList) { ... //фильтрация значений. Если проходят проверку, то счетчик увеличивается. Если нет, то - break count++; } } }); id++; } while (count < 20); As mentioned above, this dumb cycle works. But there is a problem in that after its execution, for some reason, it begins anew. And it goes on endlessly. The loop itself is inside doInBackground AsyncTask method. In this case, after the end of the cycle, the onPostExecute method is onPostExecute . And then the cycle begins again. And from the same moment where he was stopped. Those. with indices 21, 22, 23, etc. I sat with the debager for more than an hour, but could not understand why he was going into an endless cycle. AsyncTask is AsyncTask by pressing Button 'a, so the call could not loop there.
If you describe everything briefly, then everything goes according to this scenario:
Activity.AsyncTaskby pressing a key.- The loop passes the required number of times inside the
doInBackgroundand terminates. - Runs
onPostExecuteinAsyncTask. - It takes a couple of seconds and the cycle starts again from the place where it was stopped.
Where is my slip?
UPD The fact that the counter is incremented within the request itself is not a random error. It increases only after the values have passed the filter. This is exactly my gap: I need to somehow stop the cycle not after 20 passes through it, but after receiving 20 objects inside the onComplete request.
Get rid of the counter also fails: while (arrayList.size () <20) also leads to an infinite loop.
Thank you in advance for your response.