Search code examples
androidcordovaback-buttonandroid-homebutton

PhoneGap on click backbutton simulate click in home button


I'm looking for change action for backbutton, actually I'm using events to catch backbutton calls and using navigator.app.exitApp(); to close app (in really pause app), but I need backbutton call action like home button.

Why? Well, I using cordova-plugin-background-mode, and this works only when app send to background (if using navigator.app.appExit() app is paused), so I need leave app every in background.

Is possible change action of backbutton to works like home?

I want use in iPhone and Android systems


Solution

  • you can use the plugin

    https://github.com/amitsinha559/cordova-plugin-back-as-home

    and

    https://github.com/tomloprod/cordova-plugin-appminimize

    after adding the plugin you can minimize the app when ever you want like on back button click

    document.addEventListener("backbutton", onBackKeyDown, false);
    
    function onBackKeyDown() {
        // Handle the back button
        window.plugins.appMinimize.minimize();
    }
    

    Whichever suits you. Unfortunately they both are for android. you need to create plugin manually for iPhone.