Skip to content

Commit

Permalink
修复因为自定义CameraFragment引起的内存泄漏问题
Browse files Browse the repository at this point in the history
  • Loading branch information
aaatttcccc committed Aug 25, 2022
1 parent f8609fe commit 8cc36c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ protected void onDestroy() {
if (mLayoutMediator != null) {
mLayoutMediator.detach();
}
if (mSpec.getCameraSetting() != null) {
mSpec.getCameraSetting().clearCameraFragment();
}
super.onDestroy();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,30 @@ class CameraSetting : CameraSettingApi {

private val mCameraSpec: CameraSpec = cleanInstance

/**
* 赋予自定义的CameraFragment
* 如果设置则使用自定义的CameraFragment,否则使用默认的CameraFragment
* 每次使用要重新赋值,因为会在每次关闭界面后删除该Fragment
*/
var baseCameraFragment: BaseCameraFragment<CameraStateManagement,BaseCameraPicturePresenter,BaseCameraVideoPresenter>? = null

/**
* 销毁事件
*/
fun onDestroy() {
mCameraSpec.onCameraViewListener = null
this.baseCameraFragment = null
}

override fun cameraFragment(baseCameraFragment: BaseCameraFragment<CameraStateManagement,BaseCameraPicturePresenter,BaseCameraVideoPresenter>): CameraSetting {
/**
* 赋予自定义的CameraFragment
* 如果设置则使用自定义的CameraFragment,否则使用默认的CameraFragment
* 每次使用要重新赋值,因为会在每次关闭界面后删除该Fragment
*/
var baseCameraFragment: BaseCameraFragment<CameraStateManagement, BaseCameraPicturePresenter, BaseCameraVideoPresenter>? =
null

override fun cameraFragment(baseCameraFragment: BaseCameraFragment<CameraStateManagement, BaseCameraPicturePresenter, BaseCameraVideoPresenter>): CameraSetting {
this.baseCameraFragment = baseCameraFragment
return this
}

fun clearCameraFragment() {
this.baseCameraFragment = null
}

override fun mimeTypeSet(mimeTypes: Set<MimeType>): CameraSetting {
// 如果设置了高清模式,则优先以高清模式为准
if (!mCameraSpec.enableImageHighDefinition && !mCameraSpec.enableVideoHighDefinition) {
Expand Down

0 comments on commit 8cc36c7

Please sign in to comment.