title: Use Gif image in Surface view?
body: <p>I am developing an android application , in which i am using a gif images with the following code </p>
  
  <pre><code>private static byte[] streamToBytes(InputStream is) {
      ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
      byte[] buffer = new byte[1024];
      int len;
      try {
          while ((len = is.read(buffer)) &gt;= 0) {
              os.write(buffer, 0, len);
          }
      } catch (java.io.IOException e) {
      }
      return os.toByteArray();
  }
  </code></pre>
  
  <p>// In constructor of the class</p>
  
  <pre><code>is = this.context.getResources().openRawResource(R.drawable.fondo_juego_nexus);
  
              if (DECODE_STREAM) {
                    System.out.println("in if DECODE_STREAM");
                  mMovie = Movie.decodeStream(is);
              } 
  
              else {
                  byte[] array = streamToBytes(is);
                  System.out.println("in else  DECODE_STREAM");
                  mMovie = Movie.decodeByteArray(array, 0, array.length);
             }
  
  
  
  // In On Draw 
  
    long now = android.os.SystemClock.uptimeMillis();
  
          if (mMovieStart == 0) {   // first time
              mMovieStart = now;
          }
          if (mMovie != null) {
              System.out.println("in if (mMovie != null)  " + mMovie.duration());
              int dur = mMovie.duration();
              if (dur == 0) 
              {
                  dur = 1000;
                  System.out.println("in if movie if");
              }
              System.out.println("duration is  "+ dur);
              int relTime = (int)((now - mMovieStart) % dur);
              mMovie.setTime(relTime);
              System.out.println("in if displaying syd");
              mMovie.draw(canvas,120,100);
  
          }
  </code></pre>
  
  <p>and by ontouch i exit from activity like</p>
  
  <pre><code>else if(_y&lt;=60 &amp;&amp;  _x&lt;=60)
           {
  
  
               sp.play(mySound1, volume, volume, 0, 0, 1);
               sp.release();
              playr.stop();
               tme.cancel();
               act.finish();
  
  }
  </code></pre>
  
  <p>Bu when i exit activity with above method and go back to previous activity ,
  and come again to the activity where i am using gif image it does not appear , on device galaxy s2  ,  2.3.3 but on an emulator of same size of 2.2 it is fine  </p>
  
  <p>is there any problem with this approach or what way i can use to display a gif image</p>
  
  <p>what should i do to remove this error </p>