The code I'm using has a static method in the service I'm about to start that creates a wake lock that I then reference from within the started service. I took it from a discussion about WakeLocks in here and it seems to work.
private static PowerManager.WakeLock _wakeLock = null; synchronized public static PowerManager.WakeLock getLock(Context context) { if (_wakeLock == null) { //Log.i("DownloadService", "Creating wakeLock"); PowerManager mgr=(PowerManager)context.getSystemService (Context.POWER_SERVICE); _wakeLock=mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "my worker wake lock"); _wakeLock.setReferenceCounted(false); } return(_wakeLock); } On Dec 11, 12:03 am, BK <knitt...@blandsite.org> wrote: > I think I may have found an issue within the > > My understanding is that to properly hold a device awake after an > alarm is triggered you have to aquire a WakeLock in the onReceive() > event, call a Service, then perform the work in the Service, releasing > the lock within the Service when complete. > > http://groups.google.com/group/android-developers/browse_thread/threa... > > http://www.mail-archive.com/android-developers@googlegroups.com/msg66... > > This pattern can also be found in the CommonWare Advanced Android > Development book. > > I tried this, but I found that the AlarmManager, when calling the > BroadcastReceiver, runs on a separate PID than the IntentService when > started from the BroadcastReceiver's onReceive() event. This makes > the static variable on the lock manager. > > I tried this, and my logs indicate that the PID is definately not the > same, and my understanding is that the DalikVM instances act like a > standard JVM, whereby objects and variables are no shared between > JVMs. > > Furthermore, since the WakeLock is not serializable, there is really > no way to pass the reference to the lock via an "extra" in the Intent. > > Has anyone else seen this pattern work or fail? I have an example > project (with compiled APK) if you'd like to test it yourself, where > shall I post this? I have tested this on the emulator on versions 1.6 > and 2.0. -- 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