Skip to content

Commit a024fb5

Browse files
author
Daniel Novak
committed
Update README (FragmentStatePagerAdapter)
1 parent fe6b40a commit a024fb5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ Data binding is supported - extend [ViewModelBaseBindingFragment.java](library/s
9090

9191
That's it. You can then directly use ObservableField in your ViewModels. See [example](sample/src/main/java/eu/inloop/viewmodel/sample/viewmodel/SampleBindingViewModel.java).
9292

93+
Special handling for FragmentStatePagerAdapter
94+
--------
95+
The Android implementation of [FragmentStatePagerAdapter](https://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html) is removing Fragments and storing their state. This is in contrast with [FragmentPagerAdapter](https://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html) where the Fragments are just detached but not removed.
96+
We should be also removing ViewModels and storing their state to be consistent with this behaviour.
97+
98+
<b>Use [ViewModelStatePagerAdapter](library/src/main/java/eu/inloop/viewmodel/support/ViewModelStatePagerAdapter.java) instead of the default FragmentStatePagerAdapter</b>. This class is only overriding the ```destroyItem()``` method and making sure that ViewModel is removed. The state is stored/restored automatically.
99+
You can also use the stnadard FragmentStatePagerAdapter - in that case ViewModels will be kept in memory and removed only when you leave the screen (Activity finished or Fragment removed).
100+
93101
How does it work?
94102
--------
95103

0 commit comments

Comments
 (0)