On Mon, Jun 6, 2011 at 4:47 PM, Heikki <[email protected]> wrote: > In general, I've understood that the device can go to sleep at any > time when the screen is off and no application is holding a wakelock. > But based on the behaviour I've seen, I believe there are a few cases > when the platform will hold a wakelock for the application: > > * When running Activity.onCreate() > * When running BroadcastReceiver.onReceive() > > Are my assumptions correct?
I am not aware of the onCreate() scenario you list above, though it is plausible, to support incoming phone calls. The onReceive() scenario is only for AlarmManager and incoming SMS, AFAIK. > Are there other places where the platform > holds a wakelock for the app? For incoming data packets over wireless data (not WiFi). I am not aware of other patterns here. > Maybe when executing UI callbacks > originating from user interaction? There would be no need here, as the device will not fall asleep, because the user interacted with the device. > The second thing I'd like to clear up is related to network I/O. I > understand that incoming data can wake up the CPU from sleep. On wireless data. > And if you don't acquire a wakelock soon after > reading the received data, the CPU may go to sleep before your code > has processed the data. Correct. > Is the platform holding a wakelock when it reads data from network? On wireless data. > If yes, when will it release this wakelock? Your application should neither know nor care. > Is there a grace period after > data has been received, or how does the platform guarantee the > application receiving the data has gotten the chance to acquire it's > own wakelock? Ask for a WakeLock right away. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android 3.0 Programming Books: http://commonsware.com/books -- 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

