3
我认为Can't get service object (onServiceConnected never called),onServiceConnected not getting called , getting a null pointer exception和onServiceConnected never called after bindService method并没有找到答案。OnServiceConnected没有被调用
这里是我的代码
@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
}
}
和我的服务类包含什么,只有这么多,我已经展示了它吼叫
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
}
}
但lolcat我得到只有“bound
”从消息onBind()函数,但不打印“Pod: Service Connected
”,表示服务已成功启动。 和lolcat我得到NullPointerException
,也在清单文件中提到。
请解释你的解决方案! – r4jiv007 2014-05-26 12:33:01
我重写了服务类,以便onBind()返回IBinder – 2014-05-27 04:36:13