I'm trying to create a Non-cacheable fragment by setting the IsCacheableFragment attribute on my fragment. However, when I do this, the ViewModel never gets set. Using your example project I did the following.
Steps to reproduce
Set the IsCacheableFragment equal to false
[MvxFragment(typeof(MainViewModel), Resource.Id.content_frame, true, IsCacheableFragment =false)]
[Register("example.droid.fragments.ExampleRecyclerViewFragment")]
public class ExampleRecyclerViewFragment : BaseFragment<ExampleRecyclerViewModel>
{...
I get a null exception error in OnCreate of the Fragment due to the ViewModel being null
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = base.OnCreateView(inflater, container, savedInstanceState);
var recyclerView = view.FindViewById<MvxRecyclerView>(Resource.Id.my_recycler_view);
if (recyclerView != null)
{
recyclerView.HasFixedSize = true;
var layoutManager = new LinearLayoutManager(Activity);
recyclerView.SetLayoutManager(layoutManager);
}
//ViewModel is null
_itemSelectedToken = ViewModel.WeakSubscribe(() => ViewModel.SelectedItem,
(sender, args) => {
if (ViewModel.SelectedItem != null)
Toast.MakeText(Activity,
$"Selected: {ViewModel.SelectedItem.Title}",
ToastLength.Short).Show();
});
....
I'm trying to create a Non-cacheable fragment by setting the IsCacheableFragment attribute on my fragment. However, when I do this, the ViewModel never gets set. Using your example project I did the following.
Steps to reproduce
Set the IsCacheableFragment equal to false
I get a null exception error in OnCreate of the Fragment due to the ViewModel being null
Expected behavior
I thought this would allow the fragment to not be cached. I was able to achieve my desired results by doing something similar to this. http://stackoverflow.com/questions/37195393/mvxcachingfragmentcompatactivity-refresh-cached-fragment
I posted this question to stackoverflow as well. http://stackoverflow.com/questions/39111689/mvxcachingfragmentcompatactivity-with-a-non-cached-fragment
Actual behavior
The ViewModel is null in the OnCreate method of my fragment
Configuration
Version: 4.2.3