这是我的ServiceConnection:
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
Log.i("","onServiceConnected TRUE");
locationService = ((LocationService.ServiceBinder)service).getService();
}
public void onServiceDisconnected(ComponentName className) {
Log.i("","onServiceConnected TRUE DISCONNECT");
locationService = null;
}
};这永远不会被输入。我这样称呼它:
void doBindService() {
bindService(new Intent(this, LocationService.class), mConnection, Context.BIND_AUTO_CREATE);
}在my ApplicationClass onCreate中:
Intent i= new Intent(PSLocationCenter.this, LocationService.class);
startService(i);
doBindService();我在“宣言”中写道:
<service android:name=".services.LocationService" android:enabled="true"/>我是不是试图错误地绑定它?为什么不叫它。
发布于 2017-02-20 18:57:22
我知道现在有点晚了,但也许能帮上忙。这个答案是有道理的:using getApplicatinContext我必须承认它对我还不起作用,我还在寻找,但是你似乎有和他一样的问题。
https://stackoverflow.com/questions/36547327
复制相似问题