I'm trying to implement a times WakeLock in my Application, so this is
not a Service.

I want the wakelock to simply prevent screen dimming for 3 min.
Looking through the docs, this seems simple enough, but I seem to
randomly encounter a Under-Locked exception that I cannot pinpoint.

Here is my WakeLock-related code:

in onCreate:
...
        PowerManager pm = (PowerManager)
getSystemService(Context.POWER_SERVICE);
        mWakeLock =
pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG);
        // Adjust time to include user's setting
        int timeout = WAKELOCK_TIME -
Settings.System.getInt(getContentResolver(), SCREEN_OFF_TIMEOUT, 0);
        if (timeout > 0) {
                mWakeLock.acquire(timeout);
        }
...

in onDestroy:
        if (mWakeLock != null && mWakeLock.isHeld() == true) {
                        try {
                                        mWakeLock.release();
                                } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        //e.printStackTrace();
                                }

        }
        super.onDestroy();

As you can see, I wrap the release and try to only execute it when
necessary as a clean up only.  I'm assuming that since I'm aquiring
with a timeout, the PowerManager will handle the release in most cases
when the timeout expires.

I don't have a copy of the logcat at the moment, but what seems to
happen is I get the Under-Locked exception randomly, and at random
times (it's not always when WAKELOCK_TIME elapses).  The strange thing
is that the exception does not point to my code - all the entries
point to "internal" Android code.

It's hard to find examples of other people using aquire with timeouts.

Any ideas what I could be doing wrong here?

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