i have a problem with my asynctask to load the content of a url, the content made time to been load to the string and i am forced to do Thread.Sleep to wait until the content is loaded and i'm sure that's not the ri ght way, so i'm asking to you what's the right way to get the content without that
my AsynTask :
package fungames.fungames;
import android.os.AsyncTask;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.util.EntityUtils;
class GetContent extends AsyncTask<String, Void, String> {
protected String result = "";
protected int done = 0;
@Override
protected String doInBackground(String[] params) {
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(params[0]);
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "FGAPP");
HttpResponse resulte = httpClient.execute(httpPost);
HttpEntity entity = resulte.getEntity();
result = EntityUtils.toString(entity,"UTF-8");
}
catch(Exception i) {
result = i.toString();
}
done = 1;
return result;
}
protected void onPostExecute(String message) {
}
}
my Loader :
public static void Example() {
String values = Servers.Load();
}
public static String Load() {
String url = "http://example.com";
GetContent job = new GetContent();
job.execute(url);
return Do2(job);
}
public static String Do2(GetContent job)
{
String game = job.result;
if (game != "") {
return game;
}
} else {
try {
Thread.sleep(50);
} catch (Exception e) {
e.printStackTrace();
}
return Do2(job);
}
}
thanks you !