title: Android custom adapter and asyncTask not updating listView
body: <p>I've searched all the posts I can find, and none seem to help with my situation. I have an android project that uses web services to pull down hourly weather data and populate a listView with the results. </p>
  
  <p>The weird problem I'm having is that when I debug the project on my android phone, the main activity is blank and the listView isn't populated. If I run the project from android studio with my phone locked, and then unlock my phone the app opens on my phone with all of the listView properly formatted and populated.</p>
  
  <p>I feel like it's a race condition issue between the asynctask and the adapter, but I can't seem to resolve it. I tried making my asyncTask an inner private class and calling <code>notifyDataSetChanged</code> on the adapter inside the <code>onPostExecute</code> method, but to no avail. I feel it must be something simple, but I'm relatively new to Android dev, so I'm stuck.</p>
  
  <p>I have three classes that I'll post the pertinent code from</p>
  
  <p>MainActivity.java (<code>onCreate</code>)</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
      ArrayList&lt;Weather&gt; w = new ArrayList&lt;Weather&gt;();
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          DownloadWeatherTask myTask = new DownloadWeatherTask(w);
          WeatherAdapter myAdapter = new WeatherAdapter(this,w);
  
  
          ListView l = (ListView) findViewById(R.id.weatherList);
          l.setAdapter(myAdapter);
  
          myTask.execute();
      }
  }
  </code></pre>
  
  <p>WeatherAdapter.java</p>
  
  <pre><code>public class WeatherAdapter extends ArrayAdapter&lt;Weather&gt;{
  
      public WeatherAdapter(Context context, ArrayList&lt;Weather&gt; weather) {
          super(context, R.layout.item_weather, weather);
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          // Get the data item for this position
          Weather forecast = getItem(position);
          // Check if an existing view is being reused, otherwise inflate the view
          if (convertView == null) {
              convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_weather, parent, false);
          }
          // Lookup view for data population
          TextView tvTime = (TextView) convertView.findViewById(R.id.listTime);
          TextView tvDescr = (TextView) convertView.findViewById(R.id.listDescr);
          TextView tvTemp = (TextView) convertView.findViewById(R.id.listTemp);
          TextView tvHumid = (TextView) convertView.findViewById(R.id.listHumid);
          ImageView ivWeather = (ImageView)     convertView.findViewById(R.id.weatherImg);
          // Populate the data into the template view using the data object
          tvTime.setText(forecast.time);
          tvDescr.setText(forecast.description);
          tvTemp.setText(forecast.temperature+"°(F)");
          tvHumid.setText(forecast.humidity+"% humidity");
          ivWeather.setImageBitmap(forecast.weatherImg);
          // Return the completed view to render on screen
          return convertView;
      }
  
  }
  </code></pre>
  
  <p>DownloadWeatherTask.java</p>
  
  <pre><code>public class DownloadWeatherTask extends AsyncTask&lt;Void,Void,Void&gt;{
  
      ArrayList&lt;Weather&gt; data;
  
      public DownloadWeatherTask(ArrayList&lt;Weather&gt; a){
          data = a;
      }
  
      public ArrayList&lt;Weather&gt; getData() {
          return data;
      }
  
  
      protected Void doInBackground(Void...params) {
          try {
              String website =     "http://api.wunderground.com/api/1111111111111/geolookup/q/autoip.json";
              URL site = new URL(website);
              HttpURLConnection weatherUnderground = (HttpURLConnection)     site.openConnection();
              weatherUnderground.connect();
  
              JsonParser weatherParser = new com.google.gson.JsonParser();
  
              JsonElement weatherJson = weatherParser.parse(new InputStreamReader((InputStream) weatherUnderground.getContent()));
  
              JsonObject weatherObj = weatherJson.getAsJsonObject();
  
              String zip = weatherObj.get("location").getAsJsonObject().get("zip").getAsString();
              String city = weatherObj.get("location").getAsJsonObject().get("city").getAsString();
              String state = weatherObj.get("location").getAsJsonObject().get("state").getAsString();
  
              String hourly = "http://api.wunderground.com/api/111111111111/hourly/q/" + state + "/" + city + ".json";
              URL hourlySite = new URL(hourly);
              HttpURLConnection hourlyConnection = (HttpURLConnection) hourlySite.openConnection();
              hourlyConnection.connect();
  
              com.google.gson.JsonParser hourlyParser = new com.google.gson.JsonParser();
  
              JsonElement hourlyWeatherJson = weatherParser.parse(new InputStreamReader((InputStream) hourlyConnection.getContent()));
  
              JsonArray weatherArr = hourlyWeatherJson.getAsJsonObject().get("hourly_forecast").getAsJsonArray();
              int l = weatherArr.size();
  
              for (int i = 0; i &lt; l; i++) {
                  String date = weatherArr.get(i).getAsJsonObject().get("FCTTIME").getAsJsonObject().get("pretty").getAsString();
                  String temp = weatherArr.get(i).getAsJsonObject().get("temp").getAsJsonObject().get("english").getAsString();
                  String condition = weatherArr.get(i).getAsJsonObject().get("condition").getAsString();
                  String humidity = weatherArr.get(i).getAsJsonObject().get("humidity").getAsString();
                  String iconUrl = weatherArr.get(i).getAsJsonObject().get("icon_url").getAsString();
                  Bitmap icon = getBitmapFromURL(iconUrl);
                  data.add(new Weather(date, condition, temp, humidity, icon));
              }
          } catch (IOException e) {
              Log.e("Error: ",e.toString());
          }
  
          return null;
  
      }
  
  
      protected void onPostExecute(Void...params){
  
      }
  }
  </code></pre>
  
  <p>Below are links to my screenshots showing the app not populating the listView, and the app working properly when the program is run while the phone is initially locked.</p>
  
  <p><a href="https://i.stack.imgur.com/NBpuF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NBpuF.png" width="250" height="500"/></a>
  
  <a href="https://i.stack.imgur.com/ZNChm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZNChm.png" width="250" height="500"/></a>
  </p>
  
  <p>Any help would be greatly appreciated!!</p>
  
  <p>Thanks</p>