0

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?

Xonal
  • 1,340
  • 4
  • 20
  • 33

2 Answers2

0

This code looks OK to me at first glance. Are you sure it's this class that's causing the skipped frames? Are you sure that you're not doing something else on the main thread that's causing this problem?

Does your detailsDownloader class implement onPreExecute or onPostExecute? If so, you should post your code for those methods, too.

mikejonesguy
  • 9,779
  • 2
  • 35
  • 49
0

Such kind of error is usually caused by using too much UI threads, check this for more information.

Community
  • 1
  • 1
betteroutthanin
  • 7,148
  • 8
  • 29
  • 48