I have a items fragment which lists all the items and one other fragment which will use items list to create a sale document. I am using same viewModel for both of them when ever I filter items in items fragments, items in sale fragment are also filtered because data is observed in both fragments(This happens when I use activityViewModels for viewModel initialization). When I use viewModels for view model initialization then I am unable to share data in detail fragments for sale module.
ViewModel observing data changes in other fragments
432 Views Asked by Wijdan At
1
There are 1 best solutions below
Related Questions in KOTLIN
- Volatile properties in Kotlin?
- Using multiple JVM languages in the same project
- Kotlin - IntelliJ Project Setup
- Kotlin let analogue which returns the receiver
- Kotlin 'when' statement vs Java 'switch'
- Use Kotlin extension in android java class
- Kotlin stub/placeholder function for unimplemented code
- Partial class delegation in Kotlin
- SugarORM + Kotlin: Unresovled reference "listAll"
- Kotlin JS - string to number conversion?
- Where is the old Kotlin specification hosted?
- Kotlin JS - Accessing HTML DOM properties
- Access property delegate in Kotlin
- Kotlin-JS interop - using language constructs
- Does "internal" visibility modifier in Kotlin work yet?
Related Questions in ANDROID-FRAGMENTS
- Android - No view found for fragment
- Fragment AsyncTask not executing after back button pressed
- I want to Show Simple Toast Message When User Click On Media Controller button Pause/Start/Stop in video View Using Media Controller
- Call special fragment in Navigation Drawer Activity from separate Activity
- Android FragmentViewPager in Fragment
- How to restrict fragment from adding to top of stack if it already exist in the top of stack in android
- Android Studio - Illegal character 8204 error
- Adapter ListView not refreshing from Activity
- Fragment's Transaction replace on API-21 is staying behind
- Integrating Localytics - FragmentActivity
- Null pointer exception on view pager swipe
- Error:(24, 51) error: incompatible types: FragmentAcitvity cannot be converted to Fragment
- How to get menu options in actionbar aligned with fragments?
- Using Edittext in Fragment Activities outside the onCreateView method
- Clicking CardView to load a fragment
Related Questions in ANDROID-LIVEDATA
- Observe LiveData from JobService
- LiveData List doesn't update when updating database
- MutableLiveData with Kotlin multiple layler Generic not work
- Reload RecyclerView after data change with Room, ViewModel and LiveData
- setValue and postValue on MutableLiveData in UnitTest
- How can I use a view model, with sqlite and a broadcast receiver to update the UI?
- How to convert LiveData<List<Foo>> into LiveData<List<Bar>>?
- LiveData onResume not fetching new value, on pre Android 7 SDKs
- Nullability and LiveData with Kotlin
- LiveData does not call LifecycleRegistryOwner if standard Fragment is used
- LifecycleRegistryOwner class is deprecated
- Query in DAO is always returns null eventhough data exists in Database in Android-Room-LiveData-Fragments
- How to observe LiveData created by Service from UI/MainActivity/Fragments?
- Changes to LiveData of composite objects
- When unit testing a viewmodel with a repository that returns a flow, an error happen when converting it to a livedata
Related Questions in ANDROID-MVVM
- How to auto-save a form on Android - Best practices
- How do I use MVVM with bound service?
- How to create kotlin data class for this network service?
- Room Coroutine is executed in main thread
- Unable to send current city name to the API
- Android: ViewModel with paging 3 flow is leaking
- Passing query parameters to LiveData/Viewmodel in Android app
- Clear retrofit result with MVVM when fragment back
- How to implement RoomDataBase in An Activity using Dagger Hilt Injection in View Model
- How to make ViewModels communicate with same Model if I shouldn't in MVVM create Model in View?
- Android: Model mapping in repository pattern
- stateflow collect not firing in fragment
- How to create singleton object and using for UI and viewmodel for two screen in kotlin jetpack compose?
- Update the count value in Column Item Android Jetpack Compose
- LiveData observer triggering previous response
Related Questions in ANDROID-KTX
- Can we create custom Synthetic Kotlin Extensions in Android?
- this error occur when i try to build release project on android studio
- IllegalArgumentException when app start post backpressed
- Has android KTX been deprecated completely or only some parts or extensions?
- Share ViewModel used by calling Fragment to DialogFragment using by viewModels
- Compile errors after updating to WorkManager 1.0.0-alpha09
- Firestore search array contains for multiple values Android
- Object is not part of the schema for this Realm in Kotlin
- Android KTX or Anko
- Gradle build fails after adding core ktx
- Can I instantiate a user object directly using MutableLiveData in Kotlin?
- How to set -noverify option with gradle ktx for android robolectric tests?
- ViewModel observing data changes in other fragments
- How add dynamic values in Kotlin Flow
- Android ActivityViewModels - what happens when activity is destroyed
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
This is correct behaviour.
activityViewModelsis tied to an activity lifecycle which outlives fragment. So if you replace / remove / add fragments in that activity your view model lives as long as the activity does.viewModelinitialization ties it to a fragment lifecycle. If you have 2 fragments on the same screen, you have 2 different view models too - these are 2 different objects. If you replace / add / remove fragments your view model dies with its fragment.