I am working on android project where it should navigate to the previous screen when hardware back button is pressed.
Currently, my app exits instead of going back to previous screen.
What are the steps I need to do in order to navigate to the previous screen using hardware back button?
You can use ionic navigation
(ionic-nav-view). It has automatic support for android hardware back button.
Alternatively, you can register your own back button handler with $ionicPlatform
service’s ($ionicPlatform) registerBackButtonAction
method.
$ionicPlatform.registerBackButtonAction(function(e) {
// your back button handler code
}, //priority value);
Default priorities for various components provided by ionic are
PLATFORM_BACK_BUTTON_PRIORITY_VIEW = 100;
PLATFORM_BACK_BUTTON_PRIORITY_SIDE_MENU = 150;
PLATFORM_BACK_BUTTON_PRIORITY_ACTION_SHEET = 300;
PLATFORM_BACK_BUTTON_PRIORITY_POPUP = 400;
PLATFORM_BACK_BUTTON_PRIORITY_LOADING = 500;