title: Making ListView Scrolling Smooth
body: <p>I am exploring the Android developer website and reading some articles. There is one way of defering loading of images in a list view using AsyncTask:</p>
  
  <pre><code>// Using an AsyncTask to load the slow images in a background thread
  new AsyncTask&lt;ViewHolder, Void, Bitmap&gt;() {
      private ViewHolder v;
  
      @Override
      protected Bitmap doInBackground(ViewHolder... params) {
          v = params[0];
          return mFakeImageLoader.getImage();
      }
  
      @Override
      protected void onPostExecute(Bitmap result) {
          super.onPostExecute(result);
          if (v.position == position) {
              // If this item hasn't been recycled already, hide the
              // progress and set and show the image
              v.progress.setVisibility(View.GONE);
              v.icon.setVisibility(View.VISIBLE);
              v.icon.setImageBitmap(result);
          }
      }
  }.execute(holder);
  </code></pre>
  
  <p>However, to me, there seems to be a little issue with that code. Say we load the images from the Internet and they each take a couple of seconds to load.</p>
  
  <p>As a user, if we scroll the list and then switch to another activity, there are going to be some AsyncTasks running in the background and taking some bandwidth whereas we could need it in our new foreground activity.</p>
  
  <p>How do you usually handle that case using their approach? Do you kill the AsyncTask associated to a holder when recycling the view? Do you keep track in the adapter of which AsyncTasks are still running and cancel them all when activity is stopping? Some other way of doing it?</p>
  
  <p>My question is mainly about architecturing cleaning the pieces to solve that problem (not so much the implementation)</p>