Skip to content

Is it okay to pass lifeCycleOwner to viewModel function? #108

Open

Description

@Jaehwa-Noh

I just notice lifeCycleOwner passed to viewModel function.

fun startPreview(
lifecycleOwner: LifecycleOwner,
surfaceProvider: Preview.SurfaceProvider,
captureMode: CaptureMode,
cameraSelector: CameraSelector,
rotation: Int,
) {

But in the ViewModel documentation, that gives a caution that situation.
https://developer.android.com/topic/libraries/architecture/viewmodel#implement-viewmodel

Caution: A ViewModel usually shouldn't reference a view, Lifecycle, or any class that may hold a reference to the activity context. Because the ViewModel lifecycle is larger than the UI's, holding a lifecycle-related API in the ViewModel could cause memory leaks.

Is it supposed should be refactoring that related code?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions