0
votes

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 ?

1
could you post the code you use to navigate and how the presentation attributes are set on the activiteis and fragment?fmaccaroni
@fmaccaroni I edited my question with what you asked forDamien Doumer

1 Answers

0
votes

From my perspective if you really switch from signing-activity to main-activity you also have to create the View as activity. So the MainViewModel should map to the MainView as activity and should be a kind of "parent".

Fragments are part of activities.

Take a look at this example, hope it helps.

https://github.com/MvvmCross/MvvmCross/tree/master/Projects/Playground/Playground.Droid

Special to these: https://github.com/MvvmCross/MvvmCross/blob/master/Projects/Playground/Playground.Droid/Activities/RootView.cs https://github.com/MvvmCross/MvvmCross/blob/master/Projects/Playground/Playground.Droid/Activities/TabsRootView.cs