Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Trusted Contributor
Vibes
Posts: 210
Registered: ‎03-14-2012
My Carrier: AT&T
Accepted Solution

How to save preferences if user closes the app?

Hi,

 

what Adobe Air event listener do I need to use to save the users preferences if the app get closed?

 

Thank you

Vibes

Please use plain text.
Developer
jtegen
Posts: 6,529
Registered: ‎10-27-2010
My Carrier: Verizon

Re: How to save preferences if user closes the app?

[ Edited ]

It is best to save user preferences as they are changed or if you have a preference page, save them when the select the "Save" button. You can listen for the close event, but you only have a moment before it actually does get terminated so there is a chance you wont be able to save your preferences in time. This might work if you are saving just a little bit of data, but it is typically not worth it to do it at the last possible moment.

Please use plain text.
Contributor
analytik
Posts: 35
Registered: ‎08-02-2012
My Carrier: EMT (Estonia)

Re: How to save preferences if user closes the app?

As you can find in the Starship Settings sample app (this file specifically), the only thing you need to do is

 

			NativeApplication.nativeApplication.addEventListener( Event.EXITING, onApplicationExiting );

and then of course do the saving itself in onApplicationExiting().

 

 

 

Please use plain text.
Developer
shawnblais
Posts: 438
Registered: ‎10-25-2010

Re: How to save preferences if user closes the app?


analytik wrote:

As you can find in the Starship Settings sample app (this file specifically), the only thing you need to do is

 

			NativeApplication.nativeApplication.addEventListener( Event.EXITING, onApplicationExiting );

and then of course do the saving itself in onApplicationExiting().

 

 

 


 

This is poor practice, as there's no promises how long your app will stay active. Unless something has changed recently... ?

Please use plain text.
Developer
Ebscer
Posts: 813
Registered: ‎08-31-2009
My Carrier: Verizon

Re: How to save preferences if user closes the app?

Sure it is better to continuously save data, but if you do want to save on exit, this is how you do it...


Read my thoughts on BlackBerry Development at news.ebscer.com
Please use plain text.
Developer
shawnblais
Posts: 438
Registered: ‎10-25-2010

Re: How to save preferences if user closes the app?


Ebscer wrote:

Sure it is better to continuously save data, but if you do want to save on exit, this is how you do it...


Ya but you shouldn't advise anyone to ever do this unless you explain the risks.

 

This seems like a quick way to:
1. Lost someone's settings
2. End up with a corrupted file

 

As long as you're cool with that, go for it!

 

Realistically, if your save time is <100ms you are probably fine, but make sure you know what you're doing.

Please use plain text.
Developer
jtegen
Posts: 6,529
Registered: ‎10-27-2010
My Carrier: Verizon

Re: How to save preferences if user closes the app?

I still vote to never do this. Things can change in the OS where that time is reduced. Not worth having very angry users. But it is your app.
Please use plain text.
Contributor
analytik
Posts: 35
Registered: ‎08-02-2012
My Carrier: EMT (Estonia)

Re: How to save preferences if user closes the app?

[ Edited ]

Well in that case someone should ask BlackBerry for either clarification, or fixing the Starship Settings example, as it's in their official repository for everyone to learn from.

 

Edit: Also, do you have any proof of this at all? Is there any official documentation saying that the app is actually being forcefully terminated (SIGTERM, SIGKILL) as opposed to something peaceful (SIGQUIT)?

Please use plain text.
Developer
jtegen
Posts: 6,529
Registered: ‎10-27-2010
My Carrier: Verizon

Re: How to save preferences if user closes the app?

No, but it came from testing under the PlayBook QNX OS. There are several threads on this from 1-2 years ago. AIR apps do not receive the Unix signals, so it would be hard to know which signal was received.
Please use plain text.
Developer
steve_web
Posts: 318
Registered: ‎05-07-2009
My Carrier: Telus

Re: How to save preferences if user closes the app?

Since this thread is about saving settings... What does everyone recommend as the place to store the settings?

E.g. In a few of my apps I store in a file (key:value pairs) but I'd like to believe there is a better way? Some sort of settings object?

PlayBook Apps: DataMine, Dots + Boxes, 5 Marbles
BlackBerry SmartPhone Apps: 5 Marbles Soon: **** (D.Z.A), ****Quest, **** Challenge, VaultCracker, DevBrowser, Radial****
Please use plain text.