As all good PhoneGappers know you need to wait until you receive the deviceready event before you can call any of the PhoneGap API's. But, what has to happen before the deviceready event fires? Well here is breakdown of events that fire before deviceready:
- onDOMContentLoaded Internal event that is received when the web page is loaded and parsed.
- window.onload Body onload event.
- onNativeReady Internal event that indicates the PhoneGap native side is ready.
- onPhoneGapInit Internal event that kicks off creation of all PhoneGap JavaScript objects (runs constructors).
- onPhoneGapReady Internal event fired when all PhoneGap JavaScript objects have been created
- onPhoneGapInfoReady Internal event fired when device properties are available
- onPhoneGapConnectionReady Internal event fired when the connection property has been set.
- onDeviceReady User event fired to indicate that PhoneGap is ready
That may seem like a lot but you don't have to worry about it as you can't speed up the process any. That is, except in one area. The onNativeReady event does not fire until the the onPageFinished method gets called on the Android WebViewClient.
So anything you do that increases the amount of time before the web view understands the page is completely loaded will keep you from getting to deviceready. For instance if you are doing a lot of things in the window.onload method it will delay deviceready. In Pamela's particular instance she was doing an XmlHttpRequest in the onload method which delayed things.
The fix and the tip in this case is to move as many things from your onload event handler to your deviceready event handler.
So anything you do that increases the amount of time before the web view understands the page is completely loaded will keep you from getting to deviceready. For instance if you are doing a lot of things in the window.onload method it will delay deviceready. In Pamela's particular instance she was doing an XmlHttpRequest in the onload method which delayed things.
The fix and the tip in this case is to move as many things from your onload event handler to your deviceready event handler.
2 comments:
Short, succinct and to the point. Thanks a lot Simon! Great article.
Excelente Simon :)
Post a Comment