Android 从屏幕关闭调用onStop后无法绘制回收的位图
在onStop和onPause方法中,我执行以下操作:Android 从屏幕关闭调用onStop后无法绘制回收的位图,android,android-asynctask,android-imageview,android-lifecycle,Android,Android Asynctask,Android Imageview,Android Lifecycle,在onStop和onPause方法中,我执行以下操作: @Override protected void onStop() { if (backgroundBitmap != null) { backgroundBitmap.recycle(); backgroundBitmap = null; } } @Override protected void onPause() { imageServ
@Override
protected void onStop() {
if (backgroundBitmap != null) {
backgroundBitmap.recycle();
backgroundBitmap = null;
}
}
@Override
protected void onPause() {
imageService.setPauseWork(false);
imageService.setExitTasksEarly(true);
imageService.flushCache();
}
当屏幕处于关闭状态时,会暂停并调用onStop,之后会出现以下异常:
java.lang.IllegalArgumentException: Cannot draw recycled bitmaps
看来他继续画画,但位图已经准备好了
我的想法是,当由于屏幕关闭而调用onStop/onResume时,不要重新对齐位图并让imageworker继续工作。这是一个好主意还是有更好的方法?好的,我现在就用它
pm =(PowerManager) getSystemService(Context.POWER_SERVICE);
if (pm.isScreenOn() == false) { ... }
检查onResume和onStop为什么会被调用