如何自行启动服务??我不想从另一个activity.but启动服务,我想将服务绑定到活动。我的问题与此链接中所描述的完全相同。onServiceConnected never called after bindService method,即我的onserviceconnected从未被调用过。
Messenger mService = null;
public void onServiceConnected(ComponentName className, IBinder service) {
mService = new Messenger(service);
Log.d("IMSLogging", "inside onServiceConnected");
}当我执行mService.send(Msg)时,从oncreate (当然是在调用bindService之后),从创建活动调用bindService.but时,我得到了nullpointerexception。尽管bindService返回true。
发布于 2012-07-23 19:56:30
你不能调用mService.send(),直到你得到onServiceConnected()回调的之后的。这意味着你不能在onCreate()中同时使用bindService()和mService.send()。您需要将mService.send()调用移到onResume()中,或者移到onServiceConnected()或其他地方。
https://stackoverflow.com/questions/11611957
复制相似问题