0

在我的 onStop 和 onPause 方法中,我执行以下操作:

 @Override
    protected void onStop() {
        if (backgroundBitmap != null) {
          backgroundBitmap.recycle();
          backgroundBitmap = null;
        }
}

@Override
    protected void onPause() {
     imageService.setPauseWork(false);
     imageService.setExitTasksEarly(true);
     imageService.flushCache();
}

什么时候关闭屏幕 onPause 和 onStop 被调用,然后我得到这个异常:

java.lang.IllegalArgumentException: Cannot draw recycled bitmaps

所以看起来他还在继续画,但位图已经被回收了?

我的想法不是回收我的位图并让图像工作者继续做他的工作,当 onStop/onResume 因屏幕关闭而被调用时。这是一个好主意还是有更好的方法?

4

1 回答 1

0

好的,我知道了,我现在用

 pm =(PowerManager) getSystemService(Context.POWER_SERVICE);
 if (pm.isScreenOn() == false) { ... }

检查为什么 onResume 和 onStop 被调用

于 2013-10-08T20:27:34.340 回答