Software Archive
Read-only legacy content
17061 Discussions

Can't catch back button

furio_f_
Beginner
1,238 Views

Hi

 

I've a new problem with Intel XDK. In my app, i need to catch Android's back button to link to a specific page or, better, to previous page. I've tried with addvirtualpage and back button event but nothing happened. In attachment i've attach my project. Find "funzioni.js" in www/include/funcioni.js. Move to respondeSing() and read the comment.
 

0 Kudos
10 Replies
Pamela_H_Intel
Moderator
1,238 Views

Furio,

There are several issues in your code. Perhaps they are affecting your access to the back button. For example: 

    setTimeout("chiudiPopUp()", 3000);    You are passing the function as a string

    some of your variables are used out of scope

Do you use JSHint?

0 Kudos
Dale_S_Intel
Employee
1,238 Views

If you get those fixed and are still seeing a problem, it could be related to your cordova version:

https://software.intel.com/en-us/forums/intel-xdk/topic/594374

0 Kudos
furio_f_
Beginner
1,238 Views

Yes, this is my fault. I've passed the function like string because after i use string to test if app enter on function. So, modify setTimeout, clear the srcript and create another .js file only for "backbutton" event. ATM work fine but, there is a problem. When i navigate from mainpage (page when ajax print from php answer all coupon or filtered coupon) to coupon page (the page opened after the click on copun's link) and click backbutton to back to mainpage i need to click 2 times, first nothing happens, at second click addEventListener(...) catch my backbutton. Any type of answer? i attach the last project :)

 

Thx to all for previous answer,

Furio
 

0 Kudos
Pamela_H_Intel
Moderator
1,238 Views

I am glad you have made progress.

Maybe if you fix some of the other errors - "out of scope", "missing semicolon", etc. - it will be easier to find your remaining problem.funzioniJSHint_0.PNG

0 Kudos
Pamela_H_Intel
Moderator
1,238 Views

Furio,

It is possible that you are not invoking the onDeviceReady() function because the "deviceready" listener statement is not inside a function. You may want to wrap that statement inside a function that is called automatically, like onLoad(), such as in the following (as shown in the Cordova documentation):

    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // device APIs are available
    //
    function onDeviceReady() {
        // Now safe to use device APIs
    }

Also, I am still seeing 53 error messages. They may be affecting your results.

Pamela

0 Kudos
furio_f_
Beginner
1,238 Views

There are 53 error because i'm using method that include only in index.html. Example, in my "funzioni.js" i've used ajax call to retrieve information from php, obv XDK say me that are some  error because i've not included jquery library on that file.So, this isn't the problem, canu help me? Pamela i've sent to u (4/5 days ago) the zip of my proj to, can u answer ?

 

Thanks

have a nice day

0 Kudos
Pamela_H_Intel
Moderator
1,238 Views

Yes, I looked at your code. Is the onDeviceReady() function actually being called? (See my post from Monday.)

0 Kudos
furio_f_
Beginner
1,238 Views

yes , backbutton.js atm work well . The only problem is the first click. When I run the application , at first click (Android's backbutton ) Event BackButton not active , after the second click everything starts to work well .

0 Kudos
Pamela_H_Intel
Moderator
1,238 Views

Furio,

The back button event usually works pretty well with Android. I wonder if your backbutton.js code is either not listening for the event soon enough? Or maybe it is not fully processing the event the first time it catches it. Try debugging in the Debug tab - set breakpoints so that you can see what is happening and why the first event looks like it is being ignored.

Pamela

0 Kudos
Pamela_H_Intel
Moderator
1,238 Views

It sounds like you are debugging in the emulator tab. Debugging in the debug tab gives you more functionality, you can set breakpoints and step through the execution. Try that.

0 Kudos
Reply