page show event when coming back from native activity to phonegap activity

Posted: January 30, 2013 in android, javascript, jquery mobile, mobile, phonegap

I have two activities in my project:

  • native java activity
  • phonegap activity

i invoke the native activity from phonegap with normal javascript interface like in my previous post and it works fine.

After The user is done in the native activity he suppose to press the back button and the phonegap activity should understand that the native activity has finished and to try and grab a number from the native code from with javascript with the phonegap js interface.

I’m trying all kind of javascript stuff to make it happen.

i tried jqm page events, js onload, js onfocus and nothing worked so i moved to find some other solution.

I just added a refresh button on the phonegap html page to a user can manually refresh.

this is lame and i hope i will find a better solution.

ok. so now i’m updating some static integer on the native java code and when user pushes back button it can press another button ‘refresh’ that reads that static integer with phonegap js interface. pretty lame, because if the user will not   press it nothing will be updated and the database will remain unchaned.

so i typed in google “phonegap event from java” and i found this post:!topic/phonegap/WuihERTBK_M%5B1-25-false%5D

found an answe by one Simon that says

Yeah, you want to make a call to your plugin and when you send back your initial PluginResult you want to:


that way you can send multiple results back to your page. You just need to make sure to setKeepCallback to true each time you return a result.
Check out the NetworkManager code for an example:

this must be tested.

Found in the attached link some code and found the function:

194      * Create a new plugin result and send it back to JavaScript
195      *
196      * @param connection the network info to set as navigator.connection
197      */
198     private void sendUpdate(String type) {
199         if (connectionCallbackContext != null) {
200             PluginResult result = new PluginResult(PluginResult.Status.OK, type);
201             result.setKeepCallback(true);
202             connectionCallbackContext.sendPluginResult(result);
203         }
204         webView.postMessage(“networkconnection”, type);
205     }
so i guess i need to understand better what is CallbackContext for phonegap.
found some links:
ok. i guess I will create me a phonegap plugin and use the code above to update the phonegap code with new data. because I want the db to be sqlLite under phonegap. not the native.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s