You simply need to remove the uploadData(token)
call in testRequest(String token)
. When testRequest
completes, it get backs to your for loop anyway (in uploadData
), which will call testRequest
again on next iteration.
Also, if you want to stop the iteration in case one upload failed, you probably want to avoid catching all exception in testRequest
or at least make it return a boolean that would indicates if everything was ok.
private void uploadData(String token)
{
for (int i = O; i< 300 ; ++i)
{
if (!testRequest(token)) {
// To some logging
break;
}
}
}
private void testRequest(String token)
{
Log.d("result:", token);
//HttpClient httpclient = getNewHttpClient();
URI path;
try {
// UPLOAD CODE
return true;
} catch (UnsupportedEncodingException e) {
// all your catch blocks
}
return false;
}