callback/callback-android — Issue #21: PluginManager initialization
Author: dennisjzh
Created: 2011-11-10 03:34:16+00:00
State: open

My app is broken when upgrading to 1.2 from 1.1. My code that call the DroidGap.addService method causes a null reference exception to be raised. In comparing the 1.2 changes, I realized that the pluginManager initialization code has been moved from the init method to the loadUrlIntoView method. With the change, the pluginManager object is not initialized until after my page is loaded. I have to move the addService call after the loadUrl method in order to get rid of the exception.

My code before the upgrade:
addService("GwtMobile", "com.gwtmobile.phonegap.PhoneGapPlugIn");
super.loadUrl("file:///android_asset/www/index.html");

My code after the upgrade:
super.loadUrl("file:///android_asset/www/index.html");
addService("GwtMobile", "com.gwtmobile.phonegap.PhoneGapPlugIn");

While switching the order fixes the problem, I think this should be considered an issue. What if I need to access the service on the page load event? Apparently that will fail as the service is not added at that time. It makes more sense to keep the pluginmanager initialization code in the init method to ensure that service can be added before the page is loaded.