Master Detail Page Navigation Not Working On Android

SURESHGANAPATHYSURESHGANAPATHY INMember

Hi,

I have a log in page, after successful log in, it navigate to 'Master Detail' page. When I try to select an option from Master Section , it throws an error
this line 'Detail = new NavigationPage(displayPage);'
"System.Exception: Android only allows one navigation page on screen at a time".

Here i mentioning code that i used.
public class MeetingRootPage : MasterDetailPage
{
public MeetingRootPage(List data)
{
try
{
NavigationPage.SetHasNavigationBar(this, false);
var meetingPage = new MyMeetingScreen();
meetingPage.Menu.ItemSelected += (sender, e) => FilterMeetingList(e.SelectedItem as MeetingStatus);
Master = meetingPage;
Detail = new NavigationPage(new TaskScreen());
}
catch (Exception ex)
{
}
}
public void FilterMeetingList(MeetingStatus meeting)
{
CommonSetting.MeetingType = meeting.StatusName;
Page displayPage = (Page)Activator.CreateInstance(meeting.TargetType);
** Detail = new NavigationPage(displayPage);**
IsPresented = false;
if(meeting.TargetType == typeof(TrackAssignedTask))
{
NavigationPage.SetBackButtonTitle(this, "Task Screen");
};
}
}

How can i solve this issue????

Answers

  • Did you solve this error?

  • any luck solving this issue?

  • TorbenKruseTorbenKruse DEMember ✭✭✭

    like it says: Android only allows one navigation page on screen at a time

    So I guess your login page is another navigation page and you just push to the MasterDetailPage. Instead you should just have one NavigationPage and push your login page modal when a login is required. That's just a guess as I can't see where the first NavigationPage is created in your unformatted code example.

  • AlexisMouraAlexisMoura BRMember

    if (Device.OS == TargetPlatform.Android)
    Detail = (Page)Activator.CreateInstance(menuItem.TargetType);
    else
    Detail = new NavigationPage((Page)Activator.CreateInstance(menuItem.TargetType));

  • nikkanikka USMember ✭✭

    @TorbenKruse said:
    like it says: Android only allows one navigation page on screen at a time

    So I guess your login page is another navigation page and you just push to the MasterDetailPage. Instead you should just have one NavigationPage and push your login page modal when a login is required. That's just a guess as I can't see where the first NavigationPage is created in your unformatted code example.

    Imagine that we have Registration button on that Login modal. There should be a multi-step registration, involving a dozen of pages. This means that all of them should be modal. Is there any alternative?

  • @nikka Good question. I have exactly the same situation and models just aren't the way I like to solve this. Any solution?

  • nikkanikka USMember ✭✭

    @JeroenvanWarmerdam.5306 What's wrong with modals?

  • MelbourneDeveloperMelbourneDeveloper AUMember ✭✭✭
    edited February 2017

    I have this same problem. I've taken the basic Master/Detail navigation sample and slightly modified it. Now, when I navigate to the detail page, I get this error on Android. It works fine on UWP. I'm not trying to display two navigation pages at once. The main page is the app's main page and I'm just trying to set the detail.

                var mainPage = Application.Current.MainPage as MainPage;
                mainPage.Detail = new NavigationPage((Page)taskPage.SavePageUIController.PageElement);
    

    PS: I actually had this working on Android. Something changed, and now it doesn't work.

    I've debugged my code and found that nowhere in the code are multiple NavigationPages being created... The error is a lie. If I try to set the Detail of the main page to null, I get this error:
    System.ArgumentNullException: Detail cannot be set to null once a value is set.

  • michaelwarnesmichaelwarnes USMember ✭✭

    @ChristianFindlay what's in your app.cs file?

  • MelbourneDeveloperMelbourneDeveloper AUMember ✭✭✭

    @michaelwarnes , I discovered what my issue was.

    My issue turned out to be that I was setting the content of my NavigationPage to a TabbedPage, and inside the TabbedPage, I had included a NavigationPage as one of the tabs in the Children collection. I changed the Page to a ContentPage, and then the problem was solved.

  • michaelwarnesmichaelwarnes USMember ✭✭

    Well done, it's a shame that doesn't work on android, of course it will work on iOS

  • Same problem. I want to switch Page Navigation #1 and Page Navigation #2 in Xamarin Cross Platforms.

Sign In or Register to comment.