Monday, August 27, 2018

Handling Android Back button to always return Home Page in MasterDetail Page (PRISM)


A lot of us guys have been plague for years with master detail back button with Android some of us have been doing the dirty tricks (just to make back button go at Home Page) whenever it is selecting other pages. So here is the solution i have made and since i am using PRISM i had to make it clean as possible.


So we need create and  implement and IBackButtonAware interface for our viewmodels (assuming you are using MVVM framework that handles navigation) and create OnBackButtonPressed method with boolean return. for our sample page we are telling the MasterDetailPage to disable back button and make it go to Home/Main Page.

In MasterDetailPage 

In MasterDetail Page we need to override the OnBackButtonPressed and handles the back button logic, So this the code we have come up.

See It In Action 

Wrapping Up

Feel free to tweak this project to suit your need. If you have some questions go shoot me a message here and will gladly answer your questions. If you want more and advance topic you can catch us at this facebook groups  MondPH And Xamdavao.  If you want the full sample source you can check it right here LINK. enjoy coding.

No comments:

Post a Comment