Change function of Handy back button in the App
-
jonas.rausch
ParticipantHas successfully completed the online course Introduction
Has successfully completed the online course Intermediate (200)
Has successfully completed the online course Advanced (300)
5 years, 5 months 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
ModeratorHas 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)
5 years, 4 months 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
ModeratorHas 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
ParticipantHas successfully completed the online course Introduction
Has successfully completed the online course Intermediate (200)
Has successfully completed the online course Advanced (300)
5 years, 4 months ago #194735 years, 4 months 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
ParticipantHas successfully completed the online course Introduction
Has successfully completed the online course Intermediate (200)
Has successfully completed the online course Advanced (300)
5 years, 4 months 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
Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic.