切换GIF时应用程序被杀死

时间:2017-08-22 08:43:15

标签: java android java-memory-leaks

我正在编写一个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:胜利死亡:窗口{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:忽略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 =&# 39; 407',p =' 0x7d35b68420'

     

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

     

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

0 个答案:

没有答案