facebook

Definitive answer on phoneui.documentReadyHandler = function

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #328144 Reply

    cng_1
    Member

    What are the rules for placing .js functions in the name_custom.js file?

    Mainly I would like to know when to put functions inside or outside the base phoneui.documentReadyHandler = function() { } created in the skeleton name_custom.js.

    As example if I place functions that call phonegap functions inside phoneui.documentReadyHandler = function() { } they don’t work.
    So far they only work for me appended to the end of the file.

    I have seen many comments about placing .js functions in the file but no rules to putting into the phoneui.documentReadyHandler = function() { }

    Thanks in advance for comments.

    #328147

    Kale
    Member

    Hi,

    everything you put in phoneui.documentReadyHandler = function() { } will be called when the document is loaded and ready. That doesn´t mean that phonegap is loaded and functional.

    If you put a phonegap function in there, it is possible that it is not working, because the phonegap framework isn´t fully loaded at that time. To avoid this behavior use
    document.addEventListener(“deviceready”, onDeviceReady, false);
    to wait for phonegap.

    Then you can put phonegap function calls in
    function onDeviceReady(){
    }

    Kale

    #328151

    cng_1
    Member

    Thank you for the tip about framework not loaded.

    Do you know if phonegap framework is loaded by the time the phoneui.documentReadyHandler has returned ? Should we wait for it to load before returning from phoneui.documentReadyHandler all the time if we expect to use phonegap functions latter in the app?

    I have seen several postings that seem to put all of their functions in the phoneui.documentReadyHandler even if they are using them for a button action on other pages at a latter time. So if I do not want the function(s) to be called at document ready time but called at a latter time when someone presses a button then I would put my functions outside of the documentReadyHandler correct?

    #328153

    Kale
    Member

    Hi,

    as I said, the document is fully loaded before the phonegap framework is fully loaded. So you have to wait with phonegap function calls, until phonegap is ready. This can be done by putting
    document.addEventListener(“deviceready”, onDeviceReady, false);
    in phoneui.documentReadyHandler = function() { }

    You can put functions in phoneui.documentReadyHandler = function() { } and nothing will happen until they are called.
    If you put a function call in there, the function will be executed immediately after the document has loaded.

    There is a difference between a function and a function call 😉

    I personally only put code in phoneui.documentReadyHandler = function() { } when I want it to be executed when the app is started.

    Kale

    #328161

    cng_1
    Member

    Thank you Kale for explaining things more clearly.

    I have been using phonegap functions, all outside of the documentReadyHandler, for camera and file transfer with some success. The app occasionally crashes returning from phonegap after the camera function and filetransfer have completed successfully. I know this since my server receives the image.

    Have you had any similar problems or does the above problem suggest an area to look for a solution the problem?

    thank you again for your time.

    #328169

    Kale
    Member

    Hi,

    I´m running a app with camera and upload functions myself and didn´t experience any problems. I can take photos or choose from the photoalbum and send the picture to a webserver. Works fine and the app didn´t crash one time. Maybe a problem with your code?

    Kale

    #328190

    cng_1
    Member

    Yea you might think it is my code but it crashes only if it is not the first thing the app does. If I navigate to other pages of the app prior to using the camera that is when it fails. If i go to the camera app first then navigate to other pages it does not crash. Seems to me a mobione to phonegap stack issue in my case.

    #328191

    Kale
    Member

    Hi,

    I can´t reproduce this on my side. My app requires to navigate first to a page where you can either take a photo or choose a photo from the library. No crashes.

    Can you share your code with your design files?

    Kale

    #328193

    cng_1
    Member

    Thank you Kale for the suggestion to use document.addEventListener(“deviceready”, onDeviceReady, false);

    I decided just to put it in phoneui.documentReadyHandler = function() {} and make a navigator call and ignore the results just to make sure the phonegap framework was installed.

    Sure enough this seems to have solved my crash issues. The random nature of the crashes just seem to be a real-time timing or mobione / phonegap stack issue or both.

    I need to do more testing. I have just tested 4 different configurations quickly that normally crashed and they did not crash. Also the screen taps are more responsive. I was having problems slow or not at all responses to screen taps.

    So waiting on phonegap framework to load seems to be critical. I am testing on the lastest Ice Cream sandwhich Razr Maxx and it may be the cpu and gpu speeds that require waiting on the framework before actually calling any functions.

    #331809

    bharkan
    Member

    Hi,
    I just downloaded mobione trial version. I am stuck in calling the deviceready function. I created a simple HelloWorld.

    No matter what I do, I am unable to listen to deviceready

    Here is a sample that I placed in my custom_js file
    While I get the first alert, I never get the second alert.

    phoneui.documentReadyHandler = function() {
    alert(“document handler ready”);
    document.addEventListener(“deviceready”, function() {
    alert(window.device.uuid);
    }, true);
    }​

    I tried having the document.addListener event outside and onLoad in the body. But nothing seems to work. I tried it in my android 2.3 phone and I am not getting any response. I have tried in all versions of device emulators provided but in vain. Please can someone help.

    I am stuck.

    bharkan

    #331846

    support-michael
    Keymaster

    @bharkan

    investigating. Will follow up as soon as I have more info for you.

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: Definitive answer on phoneui.documentReadyHandler = function

You must be logged in to post in the forum log in