venkata harika
venkata harika

Reputation: 51

Android device back button is not working in worklight

I am adding functionality to device back button using phonegap

document.addEventListener("deviceready", onDeviceReady, false);
 WL.Logger.debug("Login init");

function onDeviceReady() {
    document.addEventListener("backbutton", onBackKeyDown, false);
 }

function onBackKeyDown() {
    alert("sample1 back button clicked");
    $('#page').load("pages/samplepage1.html", function(){
        currentPage.init();

    });
}

When i click on back button sample1.html page it shows alert("sample1 back button clicked") its wrking fine

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

      function onDeviceReady() {

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

function onBackKeyDown() {

    alert("sample2 back button clicked");   
    $('#page').load("pages/sample2.html", function(){
        currentPage.init();

    });
};

When i click on backbutton on sample2.html page it was showing alert("sample1 back button clicked") but not showing the alert("sample2 back button clicked") . I wrote this it in outside the currentPage.init= function() {} in js file wt is the problem ? wt i did mistake

pls post me if any of u know the solution thank's in advance

Upvotes: 0

Views: 1139

Answers (3)

venkata harika
venkata harika

Reputation: 51

//add back button to go back to login page

  WL.App.overrideBackButton(backFunc);
   function backFunc(){
$('#page').load(pagesHistory.pop(), function(){
    currentPage.init();

});

}

Upvotes: 1

Mark T
Mark T

Reputation: 823

I you have more the one function onBackKeyDown the event will call the first function he finds. you can view the function code while debugging in chrome or firefox.

Upvotes: 0

Idan Adar
Idan Adar

Reputation: 44516

May I ask why you are not using the Worklight-provided API to override the physical back button?

See:

Upvotes: 1

Related Questions