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
Developer
Posts: 165
Registered: ‎10-26-2010
My Device: BlackBerry® PlayBook™
My Carrier: .

Re: How to save data on application exit?

These are coming from AIR desktop, which are assumptions at this point for PlayBook. I've not tested any of them yet on the simulator, but they may be worth a shot.

 

One I added, but haven't properly tested for yet is Event.USER_IDLE. In showcase mode where Deactivate never happens, maybe it will.

 

There's also Event.MOUSE_LEAVE, which may work when switching as well or when a click/touch/tap is detected outside of your app window (it won't detect the click/touch, but may get the "new" position). I don't know how Flash/AIR interact with the system, but an AIR app on desktop can track the mouse position even when it isn't hovering over the stage. Maybe it's the same on PlayBook? If this one does work, it could have consequences while showing the menu with a swipe down (saving data and animating the menu at the same time may make the animation jerky, especially if there's a lot of data to be saved).

 

Another that I'm not sure is dispatched or not on minimize is Event.RESIZE. If the actual stage is being resized when an app is minimized, like it does when switching between portrait and landscape mode, this one may work.

 

Just for reference:

 

NativeWindowDisplayChangeEvent.DISPLAY_STATE_CHANGING

NativeWindowDisplayChangeEvent.DISPLAY_STATE_CHANGE

 

are not dipatched.

Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: How to save data on application exit?

I know this is a slightly older thread, but on the device (as of 1.0.7) this works:

NativeApplication.nativeApplication.removeEventListener(Event.EXITING, onExit);

 But it seems almost "timed". The event will start and then potentially mid-way through the function it simply stops.

 

Does anyone else notice this, or is it just the debugger right now?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to save data on application exit?

It will depend on how long it takes to save the date on this approach. You probably have about a second before the apps terminates when this event is published. You should save data as it is changed or a timed delay and not rely on this method to save data at the time the app is being terminated.
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: How to save data on application exit?

Good point
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: How to save data on application exit?

In a different (?) thread, I posted some measurements which showed you have precisely 2 seconds to save the data.

Note that, as that's not documented in any way, you can't/shouldn't count on it, however, and if my app took even one second to save I'd consider it risky would restructure to save periodically or incrementally, as jtegen said.

Also, unfortunately, with the EXIT event you couldn't use any asynchronous techniques, or show a progress bar, so those are other reasons it might be best to save at other times.

I use EXIT merely to save some minor configuration data in a SharedObject, since that's quite quick. Anything more and I'd consider other approaches.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: How to save data on application exit?

[ Edited ]

Yes, I originally wanted to prevent any constant read-write operations since I don't know the speed that it occurs at (I know on BlackBerry it goes at about the speed of "slow" Smiley Wink)

 

I ended up modifying the class that handles the data so it would ignore writing anything (which is done at every value change because I don't know what the user might try to save and am not sure if 2 sec is enough) as values were changed until there was nothing left to change. Thus deflecting the issue and and allowing me to no longer need to Exiting event.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.