Wednesday, November 10, 2010

With JavaScript Android Emulator Webkit Is More Forgiving Then Webkit on Phone

Recently I was developing a mobile application on Android platform which involves various widgets of Android along with some stuff with JavaScript and WebView (Would like to write a post on my experience with Android development - may be later). Actually I wanted to plot some graphs and for that matter I opted for jQuery and flot plugin. Flot is an amazing plugin you can get to plot some really professional graphs. Well, while plotting some of the graphs, I started with some JavaScript code and writing a JavaScript handle which basically just creates JSON objects and arrays to use as my input data to flot to plot the graphs.

As most of the Android developers, I also use Android emulator to test my code. Once I have a bit of working code, I put it on my HTC Desire to get the actual feeling. So with these graph, I wrote couple of JS function along with JS handler, I deployed my first cut of the graph to my Android 1.6 emulator (API Level 4) and launched the application. Graph got plotted as expected. So far so good. I added couple of improvements, like enabling hovers, clicks, legends etc and then again tested on emulator. It gave expected results. So now it was time to deploy it on my HTC Desire. After deploying it, when I launched the application, I could just see the white screen of WebView and nothing else. No beautiful graphs. Checked LogCat, Eclipse console, everything was fine. No error/warning messages. I again tested the same on emulator and it was working like a charm.

After doing a lot of debugging with JavaScript code (let me confess, it was more of hit-and-try) I found that I declared couple of JS variables like

    var x = 0,
    var y = 1

Notice the comma after var x = 0 ? Ideally it should be semicolon but as all developers do silly mistakes, I also had slip of finger. This was not highlighted by the Eclipse HTML editor and it worked quite well on emulator. But when it came to actual phone, this was caught and it stopped everything. Liked that WebKit/WebView is very strict, but at the same time emulator behaved differently. Also there were no logs logged in LogCat. This behavior of emulator really scared me. I know it was a mistake on my part, but at least emulator should behave in same manner as actual software does. I sincerely hope that with new upcoming updates (may be with Gingerbread) this kind of issues are resolved and we can see the consistent behavior of emulator and phone software.

Cheers !!!
- Jay

No comments :

Post a Comment

Disclaimer : This is a personal blog and all content represent what I think and it does not advocate/support/advertise any other person/company. I do not earn money or intended to do so with this blog or any of the contents the blog hosts (except the google ads which you see). If I post something here that you find helpful, that's wonderful. Just in case, if I say something stupid, the stupidity is mine, and mine alone and I can not be held for anything if you fall for such stupidity :-). I cannot be held responsible for any kind of damage that may be caused by downloading or viewing the files or information provided herewith. Anybody and everybody can use/refer the contents of this blog at their own will and of course at own risk. There is no need for any kind of approval of the author. Although it would be great if feedback is left for any such usage to the author.