I have a particular situation:
a service started by a broadcast receiver starts an activity. I want to make it possible for this activity to communicate back to the service. I have chosen to use AIDL to make it possible. Everything seems works good except for bindService()
method called in onCreate()
of the activity. bindService(), in fact, throws a null pointer exception because onServiceConnected()
is never called while onBind()
method of the service is. Anyway bindService()
returns true.
The service is obviously active because it starts the activity.
I know that calling an activity from a service could sound strange, but unfortunately this is the only way to have speech recognition in a service.
Thanks in advance
I can't make up the exact problem out of your description, so I'm going to guess here!
How can bindService()
throw a NullPointerException
? The only way this could (/should) happen is when you don't supply a Service
or a ServiceConnection
listener.
bindService()
can't throw a NullPointerException
because onServiceConnected()
isn't called. The call to onServiceConnected()
is a product of bindService()
.
So I guess you are calling a AIDL
method, before the Service
has actually bonded?