I referred to the following questions already but could not find an answer:
- Can't get service object (onServiceConnected never called),
- onServiceConnected not getting called , getting a null pointer exception, and
- onServiceConnected never called after bindService method
Here is my code:
@Override
public void onStart() {
super.onStart();
Context context = getApplicationContext();
Intent intent = new Intent(context, PodService.class);
context.bindService(intent, mPodServiceConn, Context.BIND_AUTO_CREATE);
}
private ServiceConnection mPodServiceConn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
Log.e(TAG, "Pod: Service Connected");
mPodService = IPodService.Stub.asInterface(service); //here i am getting NullPointerException
}
}
and My service class contains nothing, only this much, i have shown it bellow
public class PodService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
Log.d("bound", "bound");
return null;
}
static class PodSeviceStub extends IPodService.Stub {
//here i implemented unimplemented methods
}
}
But in lolcat i am getting only "bound
" message from onBind() function, but not printing "Pod: Service Connected
", means service is started successfully.
and in lolcat i am getting NullPointerException
and also mentioned in manifest file too.