都没有看懂我在问什么这才是正确答案: public abstract boolean stopService (Intent service) Since: API Level 1 Request that a given application service be stopped. If the service is not running, nothing happens. Otherwise it is stopped. Note that calls to startService() are not counted -- this stops the service no matter how many times it was started. Note that if a stopped service still has ServiceConnection objects bound to it with the BIND_AUTO_CREATE set, it will not be destroyed until all of these bindings are removed. See the Service documentation for more details on a service's lifecycle.
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// TODO Auto-generated method stub
Log.d("ling","bind service .....");
player=IPlayer.Stub.asInterface(service);
try {
player.addFile("");
player.setName("zhangling");
Log.d("ling",""+player.ToString());
}
catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} @Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
unbindService(conn);
}
当service销毁时候,连接就会断开,回调OnserviceDisconnected这个函数,然后解除绑定,最后销毁service
public abstract boolean stopService (Intent service) Since: API Level 1
Request that a given application service be stopped. If the service is not running, nothing happens. Otherwise it is stopped. Note that calls to startService() are not counted -- this stops the service no matter how many times it was started.
Note that if a stopped service still has ServiceConnection objects bound to it with the BIND_AUTO_CREATE set, it will not be destroyed until all of these bindings are removed. See the Service documentation for more details on a service's lifecycle.