Question

I have an IntentService started within Service. The problem is, when the Service fires intent to start IntentService, nothing happens (the intent doesnt reach the IntentService).

Details: The Service is class on its own, the IntentService is defined as an inner class within Service. The reason is to share global variables (without passing them).

My geuss on where the problem might be: All services are defined in Manifest this way: (within application tag)

<service android:name=".MyService" />
<service android:name=".ConnectionIntentService" />
<service android:name=".ListeningIntentService" />

- isnt there some problem with IntentService being inner class of Service?

Otherwise, the IntentService is started like this:

Intent Start_ConnectionIS = new Intent(this, ConnectionIntentService.class);
startService(Start_ConnectionIS);

- the startService(Start_ConnectionIS) is called within BroadcastReceiver registered within Service (so far I have not experienced any problems with this)

Was it helpful?

Solution

The Service is class on its own, the IntentService is defined as an inner class within Service

That's not going to work, unless perhaps the IntentService is a static inner class.

The reason is to share global variables (without passing them).

There are no global variables in Java. The closest analogue are static data members, and you do not need to use an inner class to "share" those.

isnt there some problem with IntentService being inner class of Service?

Your manifest claims that all of your services are standalone public classes, not inner classes.

If you elect to have a BarIntentService that is a static inner class of FooService, the syntax would be android:name=".FooService$BarIntentService". A non-static inner class cannot be used for a Service, as Android cannot create an instance of it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top