How to disable android back button handler in ONSEN-UI Phonegap?

Related searches

I am developing a phonegap application in ONSEN-UI, in which I want to disable the android back button handler. I've tried Phonegap's backbutton hadler code to disable it. But I am unable to do it. Is there any other way to do it?

My Code:

 document.addEventListener('deviceready', onDeviceReady, false);

 function onDeviceReady() {

        document.addEventListener("backbutton", function (e) {
        e.preventDefault();
        }, false);
}

This is explained in Onsen UI docs: http://onsen.io/reference/ons.html#methods-summary

Just use the method ons.disableDeviceBackButtonHandler() and it will be disabled. You can use ons.enableDeviceBackButtonHandler() to enable it again.

Cordova-specific Features, Learn what Onsen UI is all about in this advanced guide series: Cordova For Android devices, Cordova fires a backbutton event on hardware back button. onDeviceBackButton.disable(); // Disables back button handler myNavigator. I use the android backbutton in order to navigate back in my app, and when I’m on the home page, a back button click would show a prompt for the user, whether they want to close the app or not. To get this working, I had to override the default back button behaviour, and I found some tutorials for that. That works nicely.

This works for me in onsen2...I have it in my app.js

ons.ready(function () {
    ons.disableDeviceBackButtonHandler();
    document.addEventListener('backbutton', function () {}, false);
});

backbutton, To override the default back-button behavior, register an event listener for the backbutton event, Amazon Fire OS; Android; BlackBerry 10; Windows Phone 8 � Onsen UI sets handlers with default behavior for Android back button in certain elements: Dialogs: Closes the dialog if it’s cancelable (except Modals and Toasts). Navigator: Pops a page if the page stack is not empty. Splitter: Closes the menu if it’s open. If the conditions are not met, these elements will call the parent element’s handler.

Try to leave the function empty. This works perfect for me.

document.addEventListener("backbutton", androidBackKey, false);

var androidBackKey = function(){
	//stay empty
};

Pressing device back button instantly closes app when navigator's , Environment Onsen UI Version: 2.9.2 Framework: None Framework binding: None Additional libraries: None Platform: Android 7.0 Cordova, Windows 10 Chrome Find ons.notification.toast in the HTML editor and remove the timeout property, When body receives a back button event, it closes the app. Handling Back Button. You will usually want to use Android back button for some app functionality like returning to previous screen. To be able to implement your own functionality, you first need to disable exiting the app when the back button is pressed.

Try this: function onLoad() { document.addEventListener("deviceready",onDeviceReady,false); } function onDeviceReady() { document.addEventListener("backbutton",noth,false); } function noth() { }

How to disable android back button handler in ONSEN-UI Phonegap?, I am developing a phonegap application in ONSEN-UI, in which I want to disable the android back button handler. I've tried Phonegap's backbutton hadler code� Disabling back button handler. If you want to disable Onsen UI back button handlers completely, use ons.disableDeviceBackButtonHandler() function. It is useful when you want to use Cordova / PhoneGap back button handler directly.

Use this if you're using a navigator:
myNavigator.getDeviceBackButtonHandler().setListener( stopButton );
function stopButton(e) {
    try{
        myNavigator.popPage();
    }
    catch (err){
        // event.callParentHandler();
        console.log( "Stopping...." + e);
    }
}

It's another listener handled by ONSEN-UI itself that quit the app. So add a listener attached to document will not stop the app from exiting. To understand it's flow, you may check out onsenui_all.js to check out the source code.

Onsen ui:Disable device backbutton in android didnt work, I am developing an android application using Cordova and Onsenui, in whic i want to disable the android back button handler. I've tried this answer ,but didnt� It is our custom tag that represents a button. All Onsen UI branded components have the ons-prefix. Like other standard tags (or HTML elements), Onsen UI components have attributes (in this case onclick), methods and event listeners. Read more in Attributes, Properties, Methods and Events. Congratulations!

I am using onsen with phonegap 2.3 for android. The back button always exits the app, no matter what page i'm on and how many pages are in the navigator stack. It doesn't popPage. I tried using your custom listener in my angular app directive, but it doesn't seem to fire. Any idea why this may be? here is my app.js:

Disable device back button event handler. Must be called on ons.ready. enableDeviceBackButtonHandler() Enable device back button event handler. Must be called on ons.ready. enableAutoStatusBarFill() Enable status bar fill feature on iOS7 and above (except for iPhone X). Must be called before ons.ready.

Android Mobile App Development with Onsen UI and Phonegap Keep it simple, use what you already know: HTML, CSS and Javascript - to develop native looking mobile apps Rating: 4.3 out of 5 4.3 (82 ratings)

Comments
  • @zen to prevent app from closing, you can override default backbutton handler: ons.setDefaultDeviceBackButtonListener(function(){/* prompt user to exit, or just do nothing here}); as documented here: onsen.io/reference/…
  • Doesn't wok for me!Again It exits the app!