This depends on the WiFi sleep policy in effect in the device's settings.

Recent Android versions (starting with 2.3, AFAICT) appear to have the
default to keep WiFi on at all times, including when the phone goes to
sleep.

If that's the case for a particular device, you can just not worry about
this.

Otherwise, yes, you will need to acquire a WifiLock and wait for the system
to 1) power on the hardware 2) scan, connect, get IP 3) switch the routing
from mobile to WiFi data.

This setup takes about 10-20 seconds (again, based on my observations), so
if your app only needs a small amount of data, it might have higher battery
use from trying to do it over WiFi.

-- K

30 марта 2012 г. 7:08 пользователь Put_tiMe <putt...@gmail.com> написал:

> What about this situation::
>
> 1. I set an AlarmManager to wake up every 15 minutes.
> 2. I switch off the screen, and the phone goes to sleep in a few minutes.
> 3. After 15 mins, the alarm manager kicks in.
> 4. In the alarm manager handler code, can I take a wifi lock? Will this
> work?
> 5. Then after my job is done (in about 40 seconds) I'll release the wifi
> lock.
>
> Does the above stategy look okay?
>
>
> On Thursday, March 29, 2012 6:59:56 PM UTC+5:30, Mark Murphy (a Commons
> Guy) wrote:
>
>> On Thu, Mar 29, 2012 at 9:02 AM, Put_tiMe <putt...@gmail.com> wrote:
>> > I have a situation where in I use AlarmManager to wake up once in a few
>> > minutes, and switch on/off wifi.
>> > If I don't use the device for a while, then the wifi never connects to
>> the
>> > preferred wifi network.
>> > Is there anything happening with the wifi if the phone is in a sleep
>> state?
>>
>> The WiFi radio will power down. Use a WifiLock if you need WiFi. Bear
>> in mind that this increases power drain.
>>
>> --
>> Mark Murphy (a Commons Guy)
>> http://commonsware.com | http://github.com/commonsguy
>> http://commonsware.com/blog | http://twitter.com/commonsguy
>>
>> Android Training in NYC: 
>> http://marakana.com/training/**android/<http://marakana.com/training/android/>
>>
>>  --
> 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
>

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

Reply via email to