Mariano Kamp wrote:
> Now you would have two active wake locks and actually when using a naive
> approach to a static variable you would have overwritten the old wake
> lock, which would lead to the old lock not being releases which would
> lead to the phone not shutting down.

Have you tried using setReferenceCounted(true) on the WakeLock? From a
glance at the WakeLock code, you should not need to have two WakeLocks
in your case -- one reference-counted WakeLock should suffice.

In the scenario you described:

-- The activity tells the service, "yo! sync me!"

-- The service acquires the reference-counted WakeLock (count now = 1)

-- The alarm goes off and starts the service

-- The started service acquires the *same* reference-counted WakeLock
(count now = 2)

-- The work from the activity-initiated sync wraps up and releases the
WakeLock (count now = 1 and we are still locked)

-- The work from the alarm wraps up and releases the WakeLock (count now
= 0 and the lock is truly released)

Admittedly, this is all theoretical, as I haven't tried reference
counted WakeLocks, though I think I'm going to give that a shot here.

> The short story is, passing in a wake lock using a
> naive approach of a static variable doesn't work when the service can be
> started again during its runtime.

That depends on what your static variable holds. ;-)

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Training: http://commonsware.com/training.html

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to