Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Android "Back" button not working in AppShell project when called from 2nd instance of a ContentPage

$
0
0

I have created my first Xamarin Forms project with an AppShell template.

The project has a QuizContentPage which takes a Quiz object and a QuestionNumber in its constructor, that tel; the page which question to show e.g.

AppShell,xaml.cs
    MenuItemQuiz_Click  =>  await Shell.Current.Navigation.PushAsync(new QuizContentPage(new QuizModel(), 0))

On the QuizPage there is a “Next” button which executes the following:
NextButton_click => await Navigation.PushAsync(new QuizContentPage(TheQuiz, QuestionNumber +1));

this instantiates a new QuizContentPage to display the next question.

If I click on the Quiz menuitem in the appshell, a new QuizPage is shown. If I then click the android "Back" button the quiz page is closed and I am taken back to the AppShell root. All good so far.

However if I click on the "Next" button of the QuizPage to load a new instance, then the Back button does not work on the new instance. Instead an exception is thrown:

[0:] Shell: Failed to Navigate Back: System.ArgumentException: Ambiguous routes matched for: //D_FAULT_FlyoutItem4/IMPL_HomePage/HomePage/D_FAULT_QP15 matches found: //D_FAULT_FlyoutItem4/IMPL_HomePage/HomePage/D_FAULT_QP15,//D_FAULT_FlyoutItem4/IMPL_HomePage/HomePage/D_FAULT_QP15

So
AppShell - click on "Quiz" menu item
QuizContentPage(Quiz, 0) ' back button works on this page
QuizContentPage(Quiz, 1) ' back button does not work on this page

I have tried various ways of calling the first instance of the QuizContentPage but they all have the same behavior.
For example, I have tried using query parameters to tell the page what question to display and then used the following in the AppShell menu click handler:
Shell.Current.GoToAsync("QP?QID=" + i.ToString(), true)

I have registered routes for the quiz page as I do not believe menu items are in the visual hierarchy:
Routing.RegisterRoute(nameof(QuizContentPage), typeof(QuizContentPage));

Any help and tips you can provide are appreciated. New to Xamarin so have a lot to learn!


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>