you could still use onCreate/onDestroy.
Just override the onRetainNonConfigurationInstance method.
This method will be called before onDestroy.
If this method is called, remember this fact by setting a boolean to
true.

Then in the onDestroy,
  if this boolean is true, a configuration change will happen: don't
shut down the connections.
  If this boolean is false, then a real destroy takes place and shut
down the connections.

In the onCreate, you can call getLastNonConfigurationInstance() to see
if this is a brand new creation or just the start of a configuration
change.

You could even program the onRetainNonConfigurationInstance to return
an object holding your connections. Then in your onCreate, you call
getLastNonConfigurationInstance to get your connections. If the call
to getLastNonConfigurationInstance is null, then your activity was
started from 'scratch'.

On Jun 9, 1:30 pm, Max Salley <msalley....@gmail.com> wrote:
> On Jun 9, 1:02 pm, "Mark Murphy" <mmur...@commonsware.com> wrote:
>
>
>
>
>
> > > I have an app that has some network connections that are causing
> > > issues when the app closes/reopens.  I would like to close the
> > > connections when the app exits, and reinstantiate them when it opens
> > > again.  onCreate/onDestroy don't work for this purpose because they
> > > get called for the foreground activity in other situations, such as
> > > when the keyboard slides out, and the rapid succession of these calls
> > > make it impossible to reliably tear down/reopen the connections
> > > without running into race conditions.  How can I tell when the app has
> > > exited?  Is there a better way to deal with network connections?
>
> > Put them in a service, which is unaffected by the comings and goings of
> > individual activities.
>
> > --
> > Mark Murphy (a Commons Guy)http://commonsware.com
> > _The Busy Coder's Guide to Android Development_ Version 2.0 Available!
>
> Yes, but when the app closes I want to close the connections (which
> requires sending data - not just releasing the objects) regardless of
> what's holding them.  How can I tell when the app exits?- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to