1

我正在编写一个 android 应用程序,当用户单击 gif 图像时,我想在其中切换两个 gif 图像。

我已经编写了以下代码来在 gif 之间切换。

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

        }
    });

}

“setGifImageResource”的代码是

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 方法如下

@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();
    }
}

问题是当我长时间在 gif 之间切换时。应用程序崩溃,但日志中没有致命错误。只有我可以看到以下日志。

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(服务器)08-22 13:47:25.091 3704 3878 W Looper:忽略 fd 407 上不再注册的意外 epoll 事件 0x19。08-22 13:47:25.092 3704 4951 I ActivityManager: 进程 com.jijith.gifanimation (pid 27542) 已死亡 (2665,191)

08-22 13:47:25.093 3704 3878 D InputDispatcher:等待应用程序准备好输入:27542。原因:等待,因为触摸窗口的输入通道未向输入调度程序注册。该窗口可能正在被移除。08-22 13:47:25.093 3704 3878 D InputDispatcher: 找不到连接 ~ name='f737847 com.jijith.gifanimation/com.jijith.gifanimation.MainActivity (server)', fd='407', p='0x7d35b68420 '

08-22 13:47:25.098 3704 4951 W ActivityManager:强制删除 ActivityRecord{74e4a0ad0 u0 com.jijith.gifanimation/.MainActivity t195}:应用程序死亡,没有保存状态

08-22 13:47:25.220 3704 4951 I WindowManager_SurfaceController: com.android.server.wm.WindowStateAnimator.destroySurface:2905 com 调用的破坏表面 Surface(name=com.jijith.gifanimation/com.jijith.gifanimation.MainActivity)。 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

4

0 回答 0