views:

293

answers:

2

I'm using a combination of alarm (set with AlarmManager) and background service to periodically synchronize data in my application.

The only problem I have is that when sleep policy terminates Wi-Fi connection the synchronization no longer works.

Is there a way to "wake up" the Wi-Fi connection that has been put to sleep? GMail somehow manages to do that because it notifies me about new e-mail even if the phone entered sleep mode.

+1  A: 

[update]You can use a WifiLock to keep WiFi active, while holding the lock.

Using an AlarmManager and a Service says to me your service is running only for a very short time!? I think (though can't say for certain) that you should make your service a forground service (check the blog for a good way to implement this on both 1.x and 2.x+) and leave the AlarmManager out of it.

MrSnowflake
Interesting. I wasn't aware of those foreground services. Will it however solve my problem with suspended Wi-Fi connection?
Immortal
I updated the post.
MrSnowflake
I know about the WifiLock but it doesn't solve the problem. My application would have to acquire this lock and keep it indefinitely. I'd rather just wake up the connection when my app wants to sync. Anyway, I think I'll leave it as it is. If the user sets such sleep policy, he/she must be aware that sync won't work.
Immortal
A: 

hi immortal,

i am encountering the same problem. were you able to find a solution? please keep us posted.

javauser
Sorry, I didn't solve this issue, just left it as it is.
Immortal