View Full Version : Multitasking and phonegap

6 Dec 2010, 3:41 PM
Have anyone managed to get the get active code from here https://gist.github.com/491468 to work with phonegap and sencha? I'm not sure where in sencha I can listen for the event. Do I need to add the event also? I have a store I would like to reload when it gets focus after it have been inactive.

The only way I have found to do it without this code seems to be to have timeout code to check if it has been activated or not. The github solution seems to be a cleaner way.

27 Dec 2010, 1:33 PM
I modified the code to just call a function in my app and it works great.

Add this function into your app index.js

function appActive() {
alert('app active');

Then add this to your AppDelegate.m before the "* Fail Loading With Error" section:

- (void)applicationDidBecomeActive:(UIApplication *)application {
// delay of 1ms ensures code will be executed in new stack trace
// that way, event listener can't block applicationDidBecomeActive
// and crash the app
NSString *fireActiveEvent = @"window.setTimeout(appActive, 1);";

[webView stringByEvaluatingJavaScriptFromString:fireActiveEvent];