androidsystem-services

System services not available to Activities before onCreate(), but no properties instantiated


I am trying to create a service which checks if the device has an active internet connection and reports it. I have absolutely no clue what's wrong with my code.

I know this question has been asked many times, but most answers, like this, state

Now as far as I know, I avoided forementioned causes. This is my simplified code:

The error occurs on the line denoted by SECOND MARKER, which gets the system connection service and checks for wifi. This is the service which is not allowed to be called before onCreate().

Furthermore, if I remove or comment the line denoted by FIRST MARKER, the error is gone, but also, of course, the service is not started.

What could be the problem?


Solution

  • You cannot pass around a Context by serializing it in a bundle.

    In an IntentService which I assume your ConnectionService is, just use this for a valid Context.