You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by bilbosax <wa...@comcast.net> on 2018/01/03 01:59:51 UTC

Event when app regains focus

I am writing an AIR app for mobile devices, and I am using a webview ANE in
the mobile app.  The problem that I am having is that when I minimize my app
and use a couple of other apps on an iPad, and then return to my app,
sometimes the webview no longer contains content.  I would like to possibly
refresh the webview when the app regains focus, but I have no idea if an
event is fired when this happens.

1) Are any events fired on a mobile device when an app regains focus??
2) Can you force an app to completely reload when the app regains focus??


Thanks for any help!!



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/

Re: Event when app regains focus

Posted by bilbosax <wa...@comcast.net>.
OK.  Thanks for the help.  Great suggestion on the Dialogue ANE, i have just
been turning off the webview visibility and use a popup to display errors.

I read about the "error" events in the various webviews.  I just haven't
been able to figure out what makes them fire.  I wonder if a page fails to
load, if this error is fired?  That would sort of act like a timeout.



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/

Re: Event when app regains focus

Posted by "Erik J. Thomas" <er...@linqto.com>.
The events fired from the Distriqt native WebView ANE are listed in the metadata here:
[Event(name="locationChange",type="com.distriqt.extension.nativewebview.events.NativeWebViewEvent")]
[Event(name="locationChanging",type="com.distriqt.extension.nativewebview.events.NativeWebViewEvent")]
[Event(name="complete",type="com.distriqt.extension.nativewebview.events.NativeWebViewEvent")]
[Event(name="error",type="com.distriqt.extension.nativewebview.events.NativeWebViewEvent")]
[Event(name="javascriptResponse",type="com.distriqt.extension.nativewebview.events.NativeWebViewEvent")]
[Event(name="javascriptMessage",type="com.distriqt.extension.nativewebview.events.NativeWebViewEvent")]
[Event(name="touchTap",type="flash.events.TouchEvent")]
For Adobe's native StageWebView there are these events declared:
[Event(name="focusOut",type="flash.events.FocusEvent")]
[Event(name="focusIn",type="flash.events.FocusEvent")]
[Event(name="error",type="flash.events.ErrorEvent")]
[Event(name="complete",type="flash.events.Event")]
[Event(name="locationChanging",type="flash.events.LocationChangeEvent")]
[Event(name="locationChange",type="flash.events.LocationChangeEvent")]
I don't see any timeout events in either of these native web views. 

I recommend you just wrap the web view and provide APIs that make it easy to reuse in your app, like a loadUrl() method that calls the web view's loadUrl() but not until you spawn a timer. You can also then encapsulate your stage sizing logic and set options to simplify it's use, including displaying any error messaging on timeout or loading error.

But keep in mind if you are using either of these native stage views and there is an error, you cannot display an Actionscript error dialog above a stage view. It will be obscured. We got around that by using Distriqt's native Dialog ANE that provides all native OS dialogs that also appear on the stage and are visible "above" the stage view. Or you can dismiss/dispose the web view and then show the error popup. The native Dialog ANE is great though because it makes all your popups: spinners, multi-select and list selections, etc., look exactly as if they were native apps. No more need to use the flash Alert class that looks like garbage.

Cheers,

Erik

On Jan 4, 2018, at 1:22 PM, bilbosax <wa...@comcast.net> wrote:

Thanks for the info Erik, it was exactly what I was looking for!

I have one last question for you that is a little unrelated, but you
mentioned in an earlier post that you use a webview ANE and StageWebView so
I thought that you might have run into this.  Do you know if any of these
browsers have a timeout function built into them someway??  The reason I ask
is that if a user clicks a button in my app that pulls up a webview and they
have lost internet connection, the webview just sits there indefinitely
blank.  After five seconds, I would like to put up a message to check their
internet connection or some useable feedback.  My webview is very
interactive so I don't want to have to set up a timer and listen for a
page-loaded event for every function in my app.  I would much rather just
listen to a timeout event and react if necessary.  Do you have any idea if
webviews have a built-in timeout feature??



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/



Re: Event when app regains focus

Posted by bilbosax <wa...@comcast.net>.
Thanks for the info Erik, it was exactly what I was looking for!

I have one last question for you that is a little unrelated, but you
mentioned in an earlier post that you use a webview ANE and StageWebView so
I thought that you might have run into this.  Do you know if any of these
browsers have a timeout function built into them someway??  The reason I ask
is that if a user clicks a button in my app that pulls up a webview and they
have lost internet connection, the webview just sits there indefinitely
blank.  After five seconds, I would like to put up a message to check their
internet connection or some useable feedback.  My webview is very
interactive so I don't want to have to set up a timer and listen for a
page-loaded event for every function in my app.  I would much rather just
listen to a timeout event and react if necessary.  Do you have any idea if
webviews have a built-in timeout feature??



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/

Re: Event when app regains focus

Posted by "Erik J. Thomas" <er...@linqto.com>.
We optimized our polling pattern so the API we hit every 20 seconds returns only about 100 bytes representing what other APIs to call back to retrieve just what's changed. It's all done in a few milliseconds. If there are changes, we retrieve just those changes and reconcile with existing data in the app. Very fast and efficient.

I stand corrected on Android apps always running in background. That was an older version Android problem we ran into but since Marshmallow, this shouldn't be a problem for you. With both Doze and Standby, you shouldn't have to worry about your app using battery when it's not in the foreground unless you meet the criteria listed in the article.

https://www.greenbot.com/article/3027918/android/how-doze-and-app-standby-finally-fixed-android-battery-life-in-marshmallow.html <https://www.greenbot.com/article/3027918/android/how-doze-and-app-standby-finally-fixed-android-battery-life-in-marshmallow.html>

I have never tried to reduce frame rates. 

Erik

On Jan 3, 2018, at 11:54 AM, bilbosax <wa...@comcast.net> wrote:

Thanks for the information Erik. Wow, your app sounds seriously legit if you
need to query your data every 20 seconds ;) My app feels expensive enough
because of the amount of data that I am pushing, but yours sounds like it
could have become a money pit if you had not come up with this solution.  I
ended up using Flashlabs Rich Webview ANE because I have to communicate with
Javascript alot and found it not a simple task using StageWebView.

Do you know if it is necessary to reduce your framerate to save battery when
Event.DEACTIVATE is fired, or does Apple/Google suspend the app in a way
that makes this unneccessary??



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/



Re: Event when app regains focus

Posted by bilbosax <wa...@comcast.net>.
Thanks for the information Erik. Wow, your app sounds seriously legit if you
need to query your data every 20 seconds ;) My app feels expensive enough
because of the amount of data that I am pushing, but yours sounds like it
could have become a money pit if you had not come up with this solution.  I
ended up using Flashlabs Rich Webview ANE because I have to communicate with
Javascript alot and found it not a simple task using StageWebView.

Do you know if it is necessary to reduce your framerate to save battery when
Event.DEACTIVATE is fired, or does Apple/Google suspend the app in a way
that makes this unneccessary??



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/

Re: Event when app regains focus

Posted by "Erik J. Thomas" <er...@linqto.com>.
Yes, I listen for these events in several commercial mobile apps and they are reliable. I set up the listeners in the Main class initialize:
private function onInitialize(event:FlexEvent):void {
    NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, onDeactivateApp);
    NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, onActivateApp);
}
Note that by default, iOS suspends mobile apps when they are no longer in the foreground so your app won't consume battery power, but Android does not. The reason for using these listeners in my case is to turn off a Timer that causes a REST API call every 20 seconds to our web service to query for any changes to the data in the app in which case the app will make additional calls to update the changed data in the app which can be expensive from time to time. 

On Android this timer would continue making these calls from the background if I didn't stop the Timer in the onDeactivateApp handler and restart it in the onActivateApp handler.

You should have no trouble calling loadURL() on your StageWebView, or native WebView. Incidentally, I use both Distriqt native WebView ANE and the Adobe StageWebView and they are both native and act exactly the same way. In fact, I choose to use StageWebView in some cases because I have no need of any additional features found in the ANE version, and it just increases the size of the app for no good reason.

Cheers, 

Erik

On Jan 2, 2018, at 7:00 PM, bilbosax <wa...@comcast.net> wrote:

Thanks Kyle.  I just googled a bunch of information on saving state for a
better user experience that listened to some NativeApplication events on
mobile, specifically Event.EXITING.  The author claims that this method is
not 100% reliable because the events don't get thrown all the time, but this
was written back in 2011.

http://www.adobe.com/devnet/flash/articles/saving_state_air_apps.html

Does anyone know if Event.ACTIVATE and Event.DEACTIVATE has become more
reliable in NativeApplication on mobile in 2018??  Anyone ever used it??



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/



Re: Event when app regains focus

Posted by bilbosax <wa...@comcast.net>.
Thanks Kyle.  I just googled a bunch of information on saving state for a
better user experience that listened to some NativeApplication events on
mobile, specifically Event.EXITING.  The author claims that this method is
not 100% reliable because the events don't get thrown all the time, but this
was written back in 2011.

http://www.adobe.com/devnet/flash/articles/saving_state_air_apps.html

Does anyone know if Event.ACTIVATE and Event.DEACTIVATE has become more
reliable in NativeApplication on mobile in 2018??  Anyone ever used it??



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/

Re: Event when app regains focus

Posted by Kyle McKnight <ka...@gmail.com>.
1) I believe you can listen to the Event.ACTIVATE event on your
NativeApplication instance to listen for when it comes back into focus.
2) Unsure on this one.

Kyle


Kyle McKnight
Senior UI Engineer - Accesso
321.347.7318 (M)


On Tue, Jan 2, 2018 at 8:59 PM, bilbosax <wa...@comcast.net> wrote:

> I am writing an AIR app for mobile devices, and I am using a webview ANE in
> the mobile app.  The problem that I am having is that when I minimize my
> app
> and use a couple of other apps on an iPad, and then return to my app,
> sometimes the webview no longer contains content.  I would like to possibly
> refresh the webview when the app regains focus, but I have no idea if an
> event is fired when this happens.
>
> 1) Are any events fired on a mobile device when an app regains focus??
> 2) Can you force an app to completely reload when the app regains focus??
>
>
> Thanks for any help!!
>
>
>
> --
> Sent from: http://apache-flex-users.2333346.n4.nabble.com/
>