Thoughts about coding and books

PhoneGap application crashing when rotating

I have seen some apps that crash when rotating from landscape to portrait or vice versa. Beginners might not have such problem as coping original PhoneGap examples with all bloating overhead works. On hte other hand some applications that I created as new project in eclipse and wrote PhoneGap app from scratch had the rotation crash issue.

It was tracked down to one line in AndroidManifest.xml. Make sure that you have Read more about PhoneGap application crashing when rotating

Strange compile error in AndroidManifest.xml

With a few android projects in Eclipse I get compile error in AndroidManifest.xml every time I restart Eclipse. Errors are something like: Description    Resource    Path    Location    Type error: Error: No resource found that matches the given name (at ‘label’ with value ‘@string/share_name’).    AndroidManifest.xml    /MobiwsaleAdmin    line 37    Android AAPT Problem This project is done with PhoneGapRead more about Strange compile error in AndroidManifest.xml[…]

Jquery mobile mobileinit event not firing

Because Jquery mobile mobileinit event is triggered when mobile jquery starts to load then event listener must be binded before execution reach to loading jquery mobile javascript file. Usually mobileinit event is binded using selector $ from jquery like this: $(document).bind(“mobileinit”,onMobileInit); This dictates JS files loading sequence in PhoneGap and websites to be something like:Read more about Jquery mobile mobileinit event not firing[…]

Add Facebook login to PhoneGap/Cordova Android app Easiest way – UPDATED

First ensure that you have Basic PhoneGap application running on your android. Check this tutorial if needed. Official tutorial is not so good but might help you out if Phonegap Facebook tutorial here fails. For additional information go to https://github.com/davejohnson/phonegap-plugin-facebook-connect/blob/master/README.md.

  1. Download PhoneGap Facebook plugin from https://github.com/davejohnson/phonegap-plugin-facebook-connect/tree/master/www
  2. Move cdv-plugin-fb-connect.js into your android phonegap webroot assets/www
  3. Include it in index.html <script type=”text/javascript” charset=”utf-8″ src=”cdv-plugin-fb-connect.js”></script>
  4. Add <plugin name=”org.apache.cordova.facebook.Connect” value=”org.apache.cordova.facebook.ConnectPlugin” /> into res/xml/plugins.xml Read more about Add Facebook login to PhoneGap/Cordova Android app Easiest way – UPDATED

Basic PhoneGap Android app from scratch step-by-step

This tutorial assumes that you have eclipse which is set up for regular android development and you can create new android projects. Phonegap files are now named cordova

  1. Create new Android project in eclipse.
  2. Download package and extract cordova-2.6.0.jar  from zip file from http://phonegap.com/download/
  3. Add cordova-2.6.0.jar to your projects build path. In eclipse open project properties > Java Build Path > Add Jars
  4. Change main Activity superclass to DroidGap
  5. Replace setContentView(R.layout.main); with super.loadUrl(“file:///android_asset/www/index.html”);
  6. Create folder xml into the project res folder. Add there plugins.xml and cordova.xml from the package you download before.
  7. Add into AndroidManifest.xml <uses-permission android:name=”android.permission.INTERNET” /> and     <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />
  8. Create folder www into projects assets folder.
  9. Add index.html file into assets/www. File content is regular HMTL.

By now you can already run the program. Next steps are starting to use PhoneGap special HTML5 features and try accessing hardware. If It fails to run then make sure you have logcat view activated in eclipse or try in linux commandline: Read more about Basic PhoneGap Android app from scratch step-by-step

PhoneGap performance measurement results

I was wondering how much is loss in performance is one would write application in PhoneGap and javascript instead of native code. I wrote 2 very basic programs one in android and second in PhoneGap. This program did standard busy looping and common string operation indexOf in the for loop. One interesting issue i found is that when you use body onload and do not finish in time then you will get error “Application Error: The connection to the server was unsuccessful. (file:///android_asset/www/index.html)”

3 different loop times were measured in javascript and native android java. Examlpe Code in Android  was : Read more about PhoneGap performance measurement results

PhoneGap vs native Android and iPhone app performance and features

Overview PhoneGap is mobile framework that allows developers to create HTML 5 and JavaScript pages and sun these inside mobile devices. Please bear in mind that “webserver” runs inside the device. It is also possible to display external pages using plugin called ChildBrowser. While PhoneGap does not support PHP it does support javascript libraries likeRead more about PhoneGap vs native Android and iPhone app performance and features[…]