cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Native Back-Button

stefan_heitzer
Participant
0 Kudos

have a sapui5 mobile application which runs perfectly. The android device has a back button. What I want to achieve is that when you press the button the app should navigate back. In the sapui5 mobile api it is possible with this coding: 

app.back();

The question now is how I can make this? The activity of my android application has the following method:

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

     if ((keyCode == KeyEvent.KEYCODE_BACK)) {

          //Here you should navigate one view back

     }

     return super.onKeyDown(keyCode, event);

}

Is it possible to call from my activity the app variable in javascript and then tell my application to navigate back?

Greetings Stef

Accepted Solutions (1)

Accepted Solutions (1)

SergioFerrari
Active Contributor
0 Kudos

Hi Stef,

  check out following page https://sapui5.hana.ondemand.com/sdk/docs/guide/Navigation.html-  and even better, start reading from here https://sapui5.netweaver.ondemand.com/sdk/docs/guide/BestPractice.htmlfocusing on the Navigation sample.

Sergio

stefan_heitzer
Participant
0 Kudos

Hi Sergio,

so you mean by adding the following coding the navigation with my back-button works?

sap.ui.controller("view.App", {

    onInit : function() {

       

        jQuery.sap.history({

            routes: [{

                // This handler is executed when you navigate back to the history state on the path "page"
                path : "page", handler: jQuery.proxy(historyPageHandler, this)

            }],

            // The default handler is executed when you navigate back to the history state with an empty hash
            defaultHandler: jQuery.proxy(historyDefaultHandler, this)

        });     ...

sap.ui.controller("view.App", {

    ...

   

    navTo : function(id, writeHistory, navType, data) {

       

        ...

       

        // write history
        if (writeHistory === undefined || writeHistory) {

            jQuery.sap.history.addHistory("page", {id: id}, false);

}

Greetings

Stef

stefan_heitzer
Participant
0 Kudos

Hi everybody,

I found a solution for solving the problem ... I wrote a new javascript file with the following code:

function onBackKeyDown(){

     // Handle here the BackButton

}

function onDeviceReady(){

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

}

function init(){

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

}

I took this out of the phonegap api and works perfectly! Thanks for all of your help!

Greetings

Stef

Ajit_K_Panda
Product and Topic Expert
Product and Topic Expert
0 Kudos

This message was moderated.

Answers (0)