I have an object, contact, with a detailsURL String. At that URL is some JSON with more information about the contact that I need to set. The way I'm attempting to do this AsyncTask is like this:
class detailDownloader extends AsyncTask<String, Void, Void> {
String detail;
private contact c;
public detailDownloader(String detail, contact c) {
this.c = c;
this.detail = detail;
}
protected Void doInBackground(String... urls) {
String url = urls[0];
Log.d("contact", "1");
String s;
try {
InputStream in = new java.net.URL(url).openStream();
Log.d("contact", "2");
BufferedReader br2 = null;
br2 = new BufferedReader(new InputStreamReader(in, "UTF-8"));
StringBuilder sb2 = new StringBuilder();
Log.d("contact", "3");
while((s = br2.readLine()) != null) {
sb2.append(s);
}
s = sb2.toString();
JSONArray detail = new JSONArray(s);
for(int j = 0; j < detail.length(); j++){
JSONObject obj2 = detail.getJSONObject(j);
boolean favorite = obj2.getBoolean("favorite");
String email = obj2.getString("email");
String largeURL = obj2.getString("largeImageURL");
JSONObject address = obj2.getJSONObject("address");
String street = address.getString("street");
String city = address.getString("city");
String state = address.getString("state");
c.setFavorite(favorite);
c.setLargeURL(largeURL);
c.setEmail(email);
c.setStreet(street);
c.setCityState(city + ", " + state);
}
in.close();
} catch (Exception e) {
Log.e("Error", e.getMessage());
}
return null;
}
}
The detailDownloader is called by:
new detailDownloader(c.getDetailsURL(), c).execute();
But I get a response in my Log: "03-06 16:30:24.724: I/Choreographer(29237): Skipped 370 frames! The application may be doing too much work on its main thread."
Any idea how to fix this issue?