1

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.

rayman
  • 20,786
  • 45
  • 148
  • 246

2 Answers2

2

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.

Community
  • 1
  • 1
Reuben Scratton
  • 38,595
  • 9
  • 77
  • 86
  • Yes, but how would you combine between the CONNECTIVITY_ACTION and the BOOT_COMPLETED ? – rayman Oct 26 '10 at 08:50
  • 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 Oct 26 '10 at 09:03
0

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
  • 20,786
  • 45
  • 148
  • 246
  • It would be better with a `SharedPreferences` than hardcoding 20,000. But I'm sure you handled it. Thanks :-) –  Feb 28 '12 at 18:01