Android Home Button exists Ionic App

I have been able to handle the back button with the following code below which displays a toast message when the user navigates back to the last state in history and ask them to press the back button once again to exit the Ionic app.

However, when the user presses the android Home Button, instead of the Ionic app getting paused in the background like a native app, the whole app exists and when a user opens the application again to resume from where they were for example chatting or viewing their profile, the app loads and displays a splash screen again instead of returning to the previous view which the user expects since they have already opened the app and pressed the home button maybe to answer a text message or phone call.

Does anyone know how I can fix this? Or have an example of code which handles the Home Button Thank you.

Code for Back Button:point_down: need help with code for Home Button:point_up:


if ($rootScope.backButtonPressedOnceToExit) {

else if ($ionicHistory.backView()) {
else {
  $rootScope.backButtonPressedOnceToExit = true;
    "Press back button again to exit",function(a){},function(b){}
    $rootScope.backButtonPressedOnceToExit = false;
return false;