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

How to observe one livedata on two pages? #1057

Open
taknikiniga opened this issue Jun 20, 2022 · 1 comment
Open

How to observe one livedata on two pages? #1057

taknikiniga opened this issue Jun 20, 2022 · 1 comment

Comments

@taknikiniga
Copy link

i'm using navigation component in my android app. i have a search edit text on that i attach a text watcher.
when that search edit text come into focus i open a seach fragment but under seach edit text. both pages are in live state .

this code is inside my home viewmodel

 val searchMData: MutableEventLiveData<String> = MutableEventLiveData()
val searchLiveData: LiveData<String>

from home activity i post value inside my ( searchMData ) throughout textwatcher
and i want to observe ( searchLiveData ) Inside my Search Fragment.

please help......

@vpuonti
Copy link

vpuonti commented Nov 17, 2022

Please look into using activityViewModels(): https://developer.android.com/guide/fragments/communicate#viewmodel

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

No branches or pull requests

3 participants
@vpuonti @taknikiniga and others