title: Creating AnimationDrawable from assets
body: <p>I locate several .png files (frames of my animation) in <code>assets</code> folder, than I fetch them using <code>AssetManager</code> in my <code>Activity</code>'s <code>onCreate()</code> method and fill my <code>AnimationDrawable</code> with them. As described in dev guide it's impossible to start Animation in <code>onCreate()</code> method and if I need to start it immediately than I should override <code>onWindowFocusChanged()</code> method. But even in such implementation my drawable object doesn't appears on the screen. Here is the code of my Activity:</p>
  
  <pre><code>package org.example.Animation;
  
  import java.io.IOException;
  
  import android.app.Activity;
  import android.content.res.AssetManager;
  import android.graphics.drawable.AnimationDrawable;
  import android.graphics.drawable.Drawable;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.MotionEvent;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  
  public class MainActivity extends Activity {
      private LinearLayout ll;
      private ImageView image;
      private AnimationDrawable ad;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          ll = new LinearLayout(this);
  
          LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(-2, -2);
          image = new ImageView(this);
          ll.addView(image, lp);
          setContentView(ll);
  
  
          AssetManager am = getAssets();
          ad = new AnimationDrawable();
          StringBuilder sb= new StringBuilder("loader/loader-");
  
          // Fetching frames from assets
          for(int i = 1; i &lt; 11; i++) {
              sb.append(i);
              sb.append(".png");
              Log.d("DownloadImageTask", "Fetching image: " + sb.toString());         
              try {
                  Drawable d = Drawable.createFromStream(am.open(sb.toString()), null);
                  ad.addFrame(d, 500);                                        
              } 
              catch (IOException e) {
                  Log.d("ImageViewAdapter", "IOException: " + e.getMessage());
              }
              sb.delete(14, sb.length()); // 14 - is the index of first digit of frame
          }
  
          image.setBackgroundDrawable(ad);                            
      }
  
      @Override
      public void onWindowFocusChanged(boolean hasFocus) {        
          super.onWindowFocusChanged(hasFocus);
          ad.start();
      }
  } 
  </code></pre>
  
  <p>Tell me please what is wrong in my code?</p>
  
  <p><strong>P.S</strong>
  Please, don't ask me why I'm not using xml file. In shorts my main goal is to avoid uisng of R.java file.</p>