I have an old Xamarin Android project, which targeted MVVMCross 6. When the app launches, a welcome activity is loaded by MVVMcross. Then the user selects the signin button, which loads the signin activity or signup activity. Then after signin, the user is redirected to the MainActivity, which contains a home fragment. Each of the activities mentioned above has its viewmodel. The Home fragment too has its viewmodel. I use viewmodel first navigation, and before navigating from the signin/signup to the main activity's page, I close the current page first.
The issue is that, when I navigate from the signin/signup page to the main activity which contains a home fragment, There is an overlapp animation that occures in the app, and MVVMcross instantiates the MainActivity several times in a row.
When I look at the output window of Visualstudio, I see this:
(MvvmCross.Logging.MvxLog) PresentationAttribute not found for MainActivity. Assuming Activity presentation (MvxAndroid) Activity host with ViewModelType MyApp.Mobile.ViewModels.MainViewModel is not CurrentTopActivity. Showing Activity before showing Fragment for MyApp.Mobile.ViewModels.HomeViewModel Activity host with ViewModelType MyApp.Mobile.ViewModels.MainViewModel is not CurrentTopActivity. Showing Activity before showing Fragment for MyApp.Mobile.ViewModels.HomeViewModel (MvvmCross.Logging.MvxLog) PresentationAttribute not found for MainActivity. Assuming Activity presentation (MvvmCross.Logging.MvxLog) PresentationAttribute not found for MainActivity. Assuming Activity presentation
From the error message, I can understand that the main activity and its fragment are fighting the top of the navigation stack.
To navigate, I use a "IMvxNavigationService" Here is how I navigate to the MainActivity that contains the fragments of the app.
await this.navigationService.Navigate<MainViewModel>();
Here is how I attach my presenter to each fragment which is to be displayed in the main viewmodel:
[MvxFragmentPresentation(typeof(MainViewModel), Resource.Id.content_frame, true)]
public class HomeFragment : BaseTabFragment<HomeViewModel>
{
}
and BaseTabFragment has the following declaration:
public abstract class BaseTabFragment<TViewModel> : BaseFragment<TViewModel> where TViewModel : class, IMvxViewModel
And Base fragment inherits from: "MvxFragment"
I tried creating a custom MVVMcross fragment presenter, where I add the "ActivityFlags.NewTask | ActivityFlags.ClearTop | ActivityFlags.ClearTask" Flags to the top activities, but this doesn't work. Can someone please help ?