Thanks again for the clarifications.
Federico
On Wed, Apr 18, 2012 at 1:26 AM, Dianne Hackborn <[email protected]> wrote:
> On Tue, Apr 17, 2012 at 12:03 AM, Federico Paolinelli <[email protected]>
> wrote:
>>
>> Not using a service will make the connection "available to be killed"
>> if the application goes background.
>> Is that correct?
>
>
> Yes.
>
>>
>> And, if we want to close the connection when the application is no
>> longer visible, where should the connection be closed?
>> The onStop() gets called when the app goes background but also when
>> the activity gets destroyed because the user pressed the back button
>> to get to a previous activity (and in this case we don't want to close
>> the connection).
>
>
> You just want to keep track of the number of active clients to decide when
> you should be running. Have two methods:
>
> class MyConnection {
> private mStartCount;
>
> void start() {
> mStartCount++;
> if (mStartCount == 1) {
> // Bring up connection
> }
> }
>
> void stop() {
> mStartCount--;
> if (mStartCount == 0) {
> // Bring down connection
> }
> }
> }
>
> And call these in each onStart() and onStop() of the activities that are
> using the connection.
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails. All such
> questions should be posted on public forums, where I and others can see and
> answer them.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
--------
Federico
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en