My project is built with master-detail navigation. There are totally three pages in the list named as Resources, Contacts, and Login. Everything works fine in iOS, but when the user presses the Droid/WinPhone devices hardware back button, the app should exit. Is there any app-exit mechanism for Xamarin Forms which will work on all the devices.? (I mean native code not platform dependent) Thanks in advance.
As far as I know there is no native way to exit the app in Xamarin application.
The only way is to use dependency service. Override OnBackButtonPressed function in your ContentPage and check it is the last page:
protected override bool OnBackButtonPressed()
{
if(navigation.NavigationStack.Count == 1)//navigation is MainPage.Navigation
DependencyService.Get<YourDependencyInterface>().CloseApp();
}
For Android in YourAndroidDependency class:
public void CloseApp()
{
(Xamarin.Forms.Forms.Context as Activity).Finish();
}
As for WinPhone I'm not sure but I believe it can be done in same way - dependency service.