tags:

views:

20

answers:

2

Hi all, I am trying to run my service as soon as boot is completed. I know how to do it, but this is the prob:

the service is running as soon as it get the boot completed intent, but my service cant open any HttpUrlConnections

I get that error:

    10-26 09:53:50.400: ERROR/HttpHandler(1165) Host is unresolved: my.host:8080

assume the this hosts works fine as soon as i launch my service manually after boot up with a launcher.

Is there a problem with connections when the device is booting up? maybe it's not ready for opening connections while it's booting up?

any ideas? or how should I fix that??

thanks,

ray.

+2  A: 

Suggest you listen for the broadcast intent android.net.connectivity.CONNECTIVITY_ACTION . There's a working example of how to do so here on stackoverflow.

Reuben Scratton
Yes, but how would you combine between the CONNECTIVITY_ACTION and the BOOT_COMPLETED ?
rayman
I imagine you'd use BOOT_COMPLETED to start your service which would then manually register a receiver for CONNECTIVITY_ACTION. (NB: Since you're in the background you should respect and listen to ACTION_BACKGROUND_DATA_SETTING_CHANGED...)
Reuben Scratton
A: 

In the end I solved it by using a handler which delay for like 20000 seconds, the device manage to finish boot properly, and then it's available for networking.

thanks all.

rayman