The `MvxFormsDroidPagePresenter` in MvvmCross is designed to handle navigation for Xamarin.Forms pages within an Android application. However, when dealing with non-Forms calls, such as those involving native Android activities, it redirects these calls to an `MvxAndroidViewPresenter`. This allows the application to seamlessly navigate between Xamarin.Forms pages and native Android views.
Here's a detailed explanation of how `MvxFormsDroidPagePresenter` handles non-Forms calls:
1. Redirecting Non-Forms Calls: When a request is made to show a view that is not a Xamarin.Forms page (e.g., a native Android activity), the `MvxFormsDroidPagePresenter` redirects this request to an `MvxAndroidViewPresenter`. This presenter is responsible for handling the presentation logic for native Android views.
2. Implementation: To achieve this redirection, you need to create a custom presenter that extends `MvxFormsDroidPagePresenter`. In this custom presenter, you can override the `Show` method to check if the view model request is for a Xamarin.Forms view or a native Android view. If it's for a native view, you can then use the `MvxAndroidViewPresenter` to handle the presentation.
3. ViewModel Interface: One approach to differentiate between Xamarin.Forms and native Android view models is to define an interface like `IXFViewModel` that is implemented by all Xamarin.Forms view models. In your custom presenter, you can check if the view model implements this interface. If it does, you handle it as a Forms view; otherwise, you use the `MvxAndroidViewPresenter`.
4. Registration: To use your custom presenter, you need to override the `CreateViewPresenter` method in your MvvmCross setup class. This method should return an instance of your custom presenter, ensuring that it is used for all view presentations.
5. Lifecycle Management: For native Android views, you also need to manage the activity lifecycle by implementing `IMvxAndroidCurrentTopActivity` and `IMvxAndroidActivityLifetimeListener`. This ensures that MvvmCross is aware of the current top activity and can properly handle navigation and lifecycle events.
By following these steps, you can effectively handle both Xamarin.Forms and native Android views within the same application using MvvmCross.
Citations:[1] https://stackoverflow.com/questions/35912706/mvvmcross-hybrid-xamarin-forms-and-android-activity-application
[2] https://stackoverflow.com/questions/36599398/mvvmcross-with-xamarin-forms-and-masterdetail
[3] https://github.com/MvvmCross/MvvmCross/issues/2802
[4] https://support.microsoft.com/en-us/office/create-a-form-that-contains-a-subform-a-one-to-many-form-ddf3822f-8aba-49cb-831a-1e74d6f5f06b
[5] https://michaelridland.com/xamarin/mixing-xamarin-forms-mvvmcross-nativeviews/
[6] https://xamarin97.rssing.com/chan-50656755/article24666.html
[7] https://xamarin91.rssing.com/chan-50628054/all_p539.html
[8] https://www.googlecloudcommunity.com/gc/AppSheet-Q-A/System-doesn-t-generate-detail-and-form-view-for-my-table-view/m-p/527393
[9] https://stackoverflow.com/questions/38181508/login-page-with-xamarin-mvvmcross-forms-preventing-back-navigation-on-android
[10] https://help.smartsuite.com/en/articles/6267415-form-view
[11] https://www.mvvmcross.com/documentation/platform/xamarin.forms/xamarin-forms-view-presenter
[12] https://ridland2.rssing.com/chan-57660607/all_p1.html