1

I am writing an android application in which I want to switch between two gifs, when user click the gif image.

I have written the below code to switch between gifs.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    gifImageView = (GifImageView) findViewById(R.id.GifImageView);
    gifImageView.setGifImageResource(R.drawable.seat_animation0);

    gifImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            gifImageView.closeInputStream();

            animChange = !animChange;
            if(true == animChange) {
                gifImageView.setGifImageResource(R.drawable.seat_animation1);
            } else {
                gifImageView.setGifImageResource(R.drawable.seat_animation0);
            }

        }
    });

}

The code for "setGifImageResource" is

public void setGifImageResource(int id) {
    mInputStream = mContext.getResources().openRawResource(id);
    init();
}

private void init() {
    setFocusable(true);
    mMovie = Movie.decodeStream(mInputStream);
    mWidth = mMovie.width();
    mHeight = mMovie.height();

    requestLayout();
}

OnDraw method is as below

@Override
protected void onDraw(Canvas canvas) {

    long now = SystemClock.uptimeMillis();

    if (mStart == 0) {
        mStart = now;
    }

    if (mMovie != null) {

        int duration = mMovie.duration();
        if (duration == 0) {
            duration = 1000;
        }

        int relTime = (int) ((now - mStart) % duration);

        mMovie.setTime(relTime);

        mMovie.draw(canvas, 0, 0);
        invalidate();
    }
}

The problem is when I keep on switching between the gifs for long time. The application crashes, but there is NO fatal error in the logs. Only i can see the below logs.

08-22 13:47:25.091 3704 3922 I WindowManager: WIN DEATH: Window{f737847d0 u0 com.jijith.gifanimation/com.jijith.gifanimation.MainActivity} 08-22 13:47:25.091 3704 3922 D WindowManager: disposeInputChannel mInputChannel: f737847 com.jijith.gifanimation/com.jijith.gifanimation.MainActivity (server) 08-22 13:47:25.091 3704 3878 W Looper : Ignoring unexpected epoll events 0x19 on fd 407 that is no longer registered. 08-22 13:47:25.092 3704 4951 I ActivityManager: Process com.jijith.gifanimation (pid 27542) has died(2665,191)

08-22 13:47:25.093 3704 3878 D InputDispatcher: Waiting for application to become ready for input: 27542. Reason: Waiting because the touched window's input channel is not registered with the input dispatcher. The window may be in the process of being removed. 08-22 13:47:25.093 3704 3878 D InputDispatcher: failed to find connection ~ name='f737847 com.jijith.gifanimation/com.jijith.gifanimation.MainActivity (server)', fd='407', p='0x7d35b68420'

08-22 13:47:25.098 3704 4951 W ActivityManager: Force removing ActivityRecord{74e4a0ad0 u0 com.jijith.gifanimation/.MainActivity t195}: app died, no saved state

08-22 13:47:25.220 3704 4951 I WindowManager_SurfaceController: Destroying surface Surface(name=com.jijith.gifanimation/com.jijith.gifanimation.MainActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2905 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:1119 com.android.server.wm.WindowState.removeLocked:1860 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2928 com.android.server.wm.WindowManagerService.removeWindowLocked:2873 com.android.server.wm.WindowManagerService.removeWindowLocked:2683 com.android.server.wm.AppWindowToken.removeAllWindows:608 com.android.server.wm.AppWindowToken.removeAppFromTaskLocked:37

  • Have a look at the [answer](https://stackoverflow.com/a/13009659/4056108) for similar issue – chirag90 Aug 22 '17 at 08:49
  • Let me introduce u a good gif image viewer....it is for facebook and easy to use....check this out: [link](https://github.com/facebook/fresco) – Mohammad Zarei Aug 22 '17 at 08:55

0 Answers0