【发布时间】:2013-02-18 12:23:18
【问题描述】:
我已经提到了以下问题,但找不到答案:
- Can't get service object (onServiceConnected never called),
- onServiceConnected not getting called , getting a null pointer exception, 和
- onServiceConnected never called after bindService method
这是我的代码:
@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 中,我从 onBind() 函数中只收到“bound”消息,但没有打印“Pod: Service Connected”,表示服务已成功启动。
在 lolcat 中,我得到了 NullPointerException,并且在清单文件中也提到了。
【问题讨论】: