Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I be signaled that my app will quit and subsequently postpone the termination?

17 views
Skip to first unread message

mbi...@hitpointstudios.com

unread,
Apr 29, 2013, 2:24:13 PM4/29/13
to
Hello Everyone,

I am new to this forum, but it seems like the right place to ask this question. In the utility code I'm writing, I'd like to be notified that my app is about to quit and then ask the system for some time while I dump my cache into the database (through IndexedDB).

I see that there is the onunload event, but my understanding is that if I cancel that event, a dialog pops up. This is highly undesirable as I'd rather just postpone quitting (or show my own gui) until my operation is finished.

Are there apis that would allow me to do this? Any suggestions?

Thank you very much for your thoughts,

_ michael

---
Michael Bishop
Hitpoint Studios, Inc.

Michael Bishop

unread,
Apr 29, 2013, 2:28:02 PM4/29/13
to dev-w...@lists.mozilla.org
Sorry, that was the 'beforeunload' event.

_ michael

---
Michael Bishop
Hitpoint Studios
http://www.hitpointstudios.com
> _______________________________________________
> dev-webapps mailing list
> dev-w...@lists.mozilla.org (mailto:dev-w...@lists.mozilla.org)
> https://lists.mozilla.org/listinfo/dev-webapps
>
>


Kumar McMillan

unread,
Apr 30, 2013, 4:23:06 PM4/30/13
to mbi...@hitpointstudios.com, dev-w...@lists.mozilla.org

On Apr 29, 2013, at 1:24 PM, mbi...@hitpointstudios.com wrote:

> Hello Everyone,
>
> I am new to this forum, but it seems like the right place to ask this question. In the utility code I'm writing, I'd like to be notified that my app is about to quit and then ask the system for some time while I dump my cache into the database (through IndexedDB).

What do you mean exactly by quit? Here are some quit-like situations I can think of:
- user shuts down the phone
- your app is killed for using too much memory
- user swipes up to kill the app from the task switcher

I don't know of a reliable way to hook into those events. Would it be possible to periodically dump the cache to the db in the background? That might be more reliable.

>
> I see that there is the onunload event, but my understanding is that if I cancel that event, a dialog pops up. This is highly undesirable as I'd rather just postpone quitting (or show my own gui) until my operation is finished.
>
> Are there apis that would allow me to do this? Any suggestions?
>
> Thank you very much for your thoughts,
>
> _ michael
>
> ---
> Michael Bishop
> Hitpoint Studios, Inc.
> _______________________________________________
> dev-webapps mailing list
> dev-w...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-webapps

Michael Bishop

unread,
May 1, 2013, 2:02:21 PM5/1/13
to Harald Kirschner, Kumar McMillan, dev-w...@lists.mozilla.org
Yes, by quit I meant "backgrounded". Sorry for the unclear request. The page visibility API looks like what I was looking for. Thanks!

_ michael



On Tuesday, April 30, 2013 at 16:46 PM, Harald Kirschner wrote:

> Hey Michael,
>
> I recommend reacting to the https://developer.mozilla.org/en-US/docs/DOM/Using_the_Page_Visibility_API and saving the state when the app goes invisible. When queries to IDB are still ongoing assume that they will not be killed when closing the app.
>
> As Kumar pointed out, the app will only be actually killed when
>
> - Its in the background and
> - the user uses the task manager to kill it or
> - app gets garbage collected when more memory is needed
> - its in the foreground and
> - has a major memory spike
>
> In all of these cases there is nothing you can do and no event.
>
> ---
> Harald Kirschner | Partner Engineer & Web Craftsman | har...@mozilla.com (mailto:hkirs...@mozilla.com)
>
>
> On Tuesday, April 30, 2013 at 1:23 PM, Kumar McMillan wrote:
>
> >
> > On Apr 29, 2013, at 1:24 PM, mbi...@hitpointstudios.com (mailto:mbi...@hitpointstudios.com) wrote:
> >
> > > Hello Everyone,
> > >
> > > I am new to this forum, but it seems like the right place to ask this question. In the utility code I'm writing, I'd like to be notified that my app is about to quit and then ask the system for some time while I dump my cache into the database (through IndexedDB).
> >
> > What do you mean exactly by quit? Here are some quit-like situations I can think of:
> > - user shuts down the phone
> > - your app is killed for using too much memory
> > - user swipes up to kill the app from the task switcher
> >
> > I don't know of a reliable way to hook into those events. Would it be possible to periodically dump the cache to the db in the background? That might be more reliable.
> >
> > >
> > > I see that there is the onunload event, but my understanding is that if I cancel that event, a dialog pops up. This is highly undesirable as I'd rather just postpone quitting (or show my own gui) until my operation is finished.
> > >
> > > Are there apis that would allow me to do this? Any suggestions?
> > >
> > > Thank you very much for your thoughts,
> > >
> > > _ michael
> > >
> > > ---
> > > Michael Bishop
> > > Hitpoint Studios, Inc.
> > > _______________________________________________
> > > dev-webapps mailing list
> > > dev-w...@lists.mozilla.org (mailto:dev-w...@lists.mozilla.org)
> > > https://lists.mozilla.org/listinfo/dev-webapps
> > >
> >
> >
> > _______________________________________________
> > dev-webapps mailing list
> > dev-w...@lists.mozilla.org (mailto:dev-w...@lists.mozilla.org)
> > https://lists.mozilla.org/listinfo/dev-webapps
> >
> >
> >
>
>

Jonas Sicking

unread,
May 14, 2013, 1:52:30 AM5/14/13
to mbi...@hitpointstudios.com, dev-w...@lists.mozilla.org
On Mon, Apr 29, 2013 at 11:24 AM, <mbi...@hitpointstudios.com> wrote:
> Hello Everyone,
>
> I am new to this forum, but it seems like the right place to ask this question. In the utility code I'm writing, I'd like to be notified that my app is about to quit and then ask the system for some time while I dump my cache into the database (through IndexedDB).
>
> I see that there is the onunload event, but my understanding is that if I cancel that event, a dialog pops up. This is highly undesirable as I'd rather just postpone quitting (or show my own gui) until my operation is finished.
>
> Are there apis that would allow me to do this? Any suggestions?

Generally speaking it's better to dump the data to IndexedDB on a
regular basis rather than trying to do it right before the application
is closed.

Many times we close applications based on running low on memory and we
simply don't have the ability to let the app take any actions
whatsoever since we're so low on memory.

Additionally, saving data on a regular basis means that less data will
be lost if the app happens to crash for other reasons.

/ Jonas
0 new messages