How do I toggle between ContentPage and MainActivity Fragment

Universal Camera 276 Reputation points
2022-11-07T21:59:33.7+00:00

I have a ContentPage showing a Map

from my MainActivity I start a Camera Fragment

    public void BackgroundCameraSetUp()  
    {  
        SetContentView(Resource.Layout.activity_camera);  
        if (null == BundleSavedInstanceState)  
        {  
            BundleSavedInstanceState = this;  
            FragmentManager.BeginTransaction()  
                .Replace(Resource.Id.container, CameraFragment.newInstance())  
                .Commit();  
        }  
    }  

my activity_camera in Android

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
tools:context="MyCamera.MainActivity" />

while I am on my ContentPage showing the Map I can launch my MainActivity Camera Fragment successfully.

What I am struggling with is once I am in my Camera Fragment how do I Navigate back to my Map in ContentPage?

I tried without success

            App.Current.MainPage.Navigation.PopModalAsync(new MainPage());   
Developer technologies .NET Xamarin
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-11-09T03:00:13.543+00:00

    Hello,

    It is not recommended to use CameraFragement in Xamarin.Forms, as a matter of fact, using any Android Fragment in Forms is not recommended in Xamarin.Forms.

    You could refer to the following documentation and sample about how to use CameraView in Xamarin.Forms.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.