启动Service:
1.创建一个service类
Intent intent=new Intent(this,MyService.class);
startService(intent);
停止:
Intent intent2=new Intent(this,MyService.class);
stopService(intent2);
绑定:
Intent intent3==new Intent(this,MyService.class);
bindService(intent3,new ServiceConnection()){
@Override
public void on ServiceConnected(ComponentName componentName,Ibinder iBinder)
}
这里我修改了service中的onbind方法,将throw换成了return null,然后bind才不会闪退
解绑:UnBindService
unbindService(scc);//这里的参数需要将
解析:必须要bind才能unbind,否则会报错,因为unbind使用了一个参数,这个参数只有绑定时才会产生
这里启动,停止,绑定,解绑,虽然创建了多个intent,但是都是同一个条件
Ibinder:用于远程操作对象的一个基本接口