Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:21:47+00:00 2026-06-02T14:21:47+00:00

I am developing an android application , in which i am using a gif

  • 0

I am developing an android application , in which i am using a gif images with the following 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)) >= 0) {
            os.write(buffer, 0, len);
        }
    } catch (java.io.IOException e) {
    }
    return os.toByteArray();
}

// In constructor of the class

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);

        }

and by ontouch i exit from activity like

else if(_y<=60 &&  _x<=60)
         {


             sp.play(mySound1, volume, volume, 0, 0, 1);
             sp.release();
            playr.stop();
             tme.cancel();
             act.finish();

}

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

is there any problem with this approach or what way i can use to display a gif image

what should i do to remove this error

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:21:49+00:00Added an answer on June 2, 2026 at 2:21 pm

    I got the solution for my problem , i do not know how good it is ,
    but it worked for me earlier i was using this code in constructor

     if (DECODE_STREAM) {
                    mMovie = Movie.decodeStream(is);
                } else {
                    byte[] array = streamToBytes(is);
                    mMovie = Movie.decodeByteArray(array, 0, array.length);
                }   
    
            }
    

    It was workign fine first time, but i think in second time it was running out of memory due to
    too much of garbage collector which was running implicitly
    and my image initialization was also running again and again which was the cause of the
    bad performance of the game ,and
    what i did was that i just added
    the garbage collector manually with

    System.gc();
    

    and initialized all images after this and also
    placed the following code

    if (DECODE_STREAM) {
                    mMovie = Movie.decodeStream(is);
                } else {
                    byte[] array = streamToBytes(is);
                    mMovie = Movie.decodeByteArray(array, 0, array.length);
                }   
    
            }
    

    after this
    which avoided the implicit running of garbage collector

    and now the gif image is working fine

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing an Android application that fetches images using http requests. It would
Im developing an Android application which are using an webservice to fetch an image
I'm developing one android application in which I'm using one customized ListView which extends
I am developing an Android application in which the user logs in using its
I am developing an application which is using facebook sdk for android to log
I'm developing an Android application that makes a Query using Activity.managedQuery() , which takes
We've been developing an Android application which includes Google Adsense. However there seems to
I'm developing an Android application which involves reading pdf files. Initially on syncing with
I am developing an Android application which makes use of the Osmdroid maps api.
I am developing android application in which i have to open option menu from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.