Here is the deal,
I am doing a web call in one of my apps. I am using a ResponseHandler to get some JSON information.
Here is the call.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_safari);
Intent intent = getIntent();
int safariId = intent.getIntExtra("safariId", -1);
String url = getString(R.string.base_url) + "/safari.php?id=" + safariId;
WebServiceClientHelper.doGet(url, new ResponseHandler() {
@Override
public void onResponse(Response r) {
try {
JSONObject jsonResponse = new JSONObject(r.getData());
safari = new SafariWithMediaUrls(jsonResponse);
loadSafari();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
Here is the WebServiceClientHelper()
@SuppressWarnings("unchecked")
public static void doGet(String url, ResponseHandler responseHandler) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("url", url);
params.put("method", "GET");
params.put("responseHandler", responseHandler);
new DoRequestTask().execute(params);
}
Here is the called constructer:
public SafariWithMediaUrls(JSONObject jsonObject) {
super(jsonObject);
try {
if (jsonObject.has("header_media_type")) {
this.setHeaderMediaType(jsonObject.getString("header_media_type"));
}
if (jsonObject.has("header_media_url")) {
this.setHeaderMediaUrl(jsonObject.getString("header_media_url"));
}
if (jsonObject.has("footer_media_type")) {
this.setFooterMediaType(jsonObject.getString("footer_media_type"));
}
if (jsonObject.has("footer_media_url")) {
this.setFooterMediaUrl(jsonObject.getString("footer_media_url"));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Sometimes using WI-FI this works instantly, sometimes it does not work at all. It just waits. Wait is it waiting for. The webserver with the JSON is always up and I can get the JSON in a browser just by typing the url correctly. WHY DOES THIS TAKE SOOOOOOO LONGGGGG the JSON is like 200 characters. Keep in mind that sometimes it works instantly and correctly.
Anything obvious?? THanks!
0 comments:
Post a Comment