Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you tell me why Application Context is used in ViewModel? #19

Open
easyhooon opened this issue Jan 29, 2024 · 2 comments · May be fixed by #39
Open

Can you tell me why Application Context is used in ViewModel? #19

easyhooon opened this issue Jan 29, 2024 · 2 comments · May be fixed by #39
Assignees

Comments

@easyhooon
Copy link

easyhooon commented Jan 29, 2024

https://github.com/android/socialite/blob/main/app/src/main/java/com/google/android/samples/socialite/ui/camera/CameraViewModel.kt
https://github.com/android/socialite/blob/main/app/src/main/java/com/google/android/samples/socialite/ui/videoedit/VideoEditScreenViewModel.kt

I'm curious about the reason for directly handling Toast message events in the ViewModel by injecting the Application Context, especially since it's possible to handle these events in the view using Channel, SharedFlow, or StateFlow.(Using a method of emitting and collecting to events)

As this approach is used in the official Android sample repository, does it imply that injecting the Application Context into the ViewModel and handling context-required operations directly within the ViewModel is more recommended than the previously mentioned three methods?

@hoc081098
Copy link

I have the same think.
Toast should be showed in the View side

@donovanfm donovanfm self-assigned this Jan 31, 2024
@donovanfm
Copy link
Contributor

Hi, thanks for taking a look at our sample! I will update the ViewModels to move away from passing in the Context. Great catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants