Android 如何使用服务
我需要一个服务,运行在不同的进程和启动启动 我的应用程序也应该与此进行通信 另外,我不想让其他应用程序使用我的服务 有办法吗Android 如何使用服务,android,Android,我需要一个服务,运行在不同的进程和启动启动 我的应用程序也应该与此进行通信 另外,我不想让其他应用程序使用我的服务 有办法吗 private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder binder) { service = ((BoxService.MyBinder) b
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder binder) {
service = ((BoxService.MyBinder) binder).getService();
Toast.makeText(mainActivity.this, "Connected", Toast.LENGTH_SHORT)
.show();
}
public void onServiceDisconnected(ComponentName className) {
service = null;
}
};
void doBindService() {
bindService(new Intent(this, BoxService.class), mConnection,
Context.BIND_AUTO_CREATE);
}
当我在我的进程中使用服务时,这很有效,但当我想在不同的进程中使用服务时,我会在绑定中出错
我能做什么?
请参阅此链接
AddFenceActivity.this.startService(new Intent(
AddFenceActivity.this, Location_Services.class));