Start a new topic

onExit() , Avoid to close the AR on "BackButton" - Wikitude - PhoneGap

onExit() , Avoid to close the AR on "BackButton" - Wikitude - PhoneGap


Hello,

I am using Wikitude SDK + PhoneGap,

I have got the icons to show on the screen, it works fine!

Now I need to avoid to blose the ARBrowser on "BackButton"...

I have added to the "HelloWorld.html" example the line below...

 

AR.context.onExit = function {

alert('Test!!!');

return false;

}

 

but this solution isn't working.

 

Then I have tried the phonegap solution:

http://docs.phonegap.com/en/2.0.0/cordova_events_events.md.html#backbutton

 

adding the script ref

<script type="text/javascript" charset="utf-8" src="../www/cordova-2.0.0.js"></script> 

then the following code into the "HelloWorld.html" page




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

function onDeviceReady() {

document.addEventListener("menubutton", onMenuKeyDown, false);

}

function onBackKeyDown() {

        navigator.notification.confirm(

            'Do You want to Close the Application?',   // message

            onConfirm,              // callback to invoke with index of button pressed

            'Close',                    // title

            'No,Yes'                   // buttonLabels

        );

        return false;

}

function onConfirm(button) {

        if (button==2) navigator.app.exitApp();

}

 

but it din't work... I have tested other PhoneGap methods  with no success..

Could you please help me to sort this?

 

Thank you for you help

Hi there!

You must know that PhoneGap commands are not working inside an ARchitect-HTML file.
You can add listeners in any JS inside the SampleProject's "www"-folder according PhoneGaps documentation
Whereat the "world"-folder contains all Wikitude Related components that work as documented in the "Library Reference" you can find in the ARchitect Tools.zip.

Cheers,
Andi

Hi Andi,

even iuf I add this code in the event listener on the idex.html page ...

what happen then is that...

the wikitude plugin close down, and the event listener works for the index.html page.

how can I avoid this?


Thanks

 

 

Hi there!

Now I understand ;-)

Please overwrite backbutton behavior of the WikitudePlugin's Android-Backbutton behavior (compare line #44 and #81 in WikitudePlugin.js for Android :

 




/* your very own backbutton implementation, if not set: AR view is closed */

function myBackbuttonCallback(){
// alert("user pressed back-button");
};





 

/*somewhere in your PhoneGap's JS code */
WikitudePlugin.onPressedBackButton(myBackbuttonCallback);





Hope that helps

Cheers,
Andi

Thank you Andi,

it worked fine ;)
Login or Signup to post a comment