Change function of Handy back button in the App
-
Ralf
5 years ago #18884I want to use the “back button” on my handy to go back one site or one screen , but if i use it , the app wants to end the app.
can anybody help?
jonas.rausch
Has successfully completed the online course Introduction
Has successfully completed the online course Intermediate (200)
Has successfully completed the online course Advanced (300)
5 years ago #18890::Hi Ralf,
The Device Button events like “back” and “home” can be detected and overwritten via JQuery/JS:
You can add this line of code to the onInit event pf your first screen:
document.addEventListener(‘backbutton’, function(){
//do stuff here
}Be Aware that overwriting the event will supress the native functions of the button, if you want to exit the app, you will need to code that yourself.
Dinkel
Has successfully completed the online course Introduction
Has successfully completed the online course Intermediate (200)
Has successfully completed the online course Advanced (300)
Has successfully completed the online course Basics (100)
4 years ago #19490::You have to bind this.
document.addEventListener("backbutton", onBackKeyDown.bind(this), false); function onBackKeyDown() { var curr_page = sap.ui.getCore().byId("Application").getCurrentPage(); console.info(curr_page.getId()); if (curr_page.getId() === "PAGE1") { console.info('close pressed'); window.navigator.app.exitApp(); // OK } else { console.info('back pressed'); // window.navigator.app.backHistory(); // <no action this.navBack(); // Uncaught TypeError this.navBack is not a function // window.navigator.app.navBack(); // Uncaught TypeError window.navigator.app.navBack is not a function } }
Dinkel
Has successfully completed the online course Introduction
Has successfully completed the online course Intermediate (200)
Has successfully completed the online course Advanced (300)
Has successfully completed the online course Basics (100)
jonas.rausch
Has successfully completed the online course Introduction
Has successfully completed the online course Intermediate (200)
Has successfully completed the online course Advanced (300)
Ralf
5 years ago #19489::Ok, this Script works,
document.addEventListener("backbutton", onBackKeyDown, false); function onBackKeyDown() { var curr_page = sap.ui.getCore().byId("Application").getCurrentPage(); console.info(curr_page.getId()); if (curr_page.getId() === "PAGE1") { console.info('close pressed'); window.navigator.app.exitApp(); // OK } else { console.info('back pressed'); // window.navigator.app.backHistory(); // <no action this.navBack(); // Uncaught TypeError this.navBack is not a function // window.navigator.app.navBack(); // Uncaught TypeError window.navigator.app.navBack is not a function } }
but this.navBack(); and the other variations doesn´t.
Any Idea why?jonas.rausch
Has successfully completed the online course Introduction
Has successfully completed the online course Intermediate (200)
Has successfully completed the online course Advanced (300)
Ralf
5 years ago #19467::document.addEventListener("backbutton", onBackKeyDown, false); function onBackKeyDown() { // Handle the back button //alert('Back Button is Pressed!'); if ("{actual Screen}"=== "Main") { console.info('close pressed'); // Backbutton -> close App } else { console.info('back pressed'); // NavTo history.back or backtoMain } }
This works, but i don´t know how to handle the if-command and Backbutton in SAPUI…
Need help how i ask for actual Screen and the commands how i go history (window) back and close app
You must be logged in to reply to this topic.