生命周期
启动方式:start&绑定。start:onCreate()–>onStartCommand()–>onDestory()。
绑定:onCreate()–>onBind()–>onDestory()。
绑定流程:继承Service,注册,提供Binder实现类。Activity中创建ServiceConnection匿名类,调用bindService();
清单属性
<service android:name=""
android:exported="" //是否可以被其他应用调用
android:enable="" //是否禁用
android:discribption="" //描述
android:directBootAware="" //结束设备之前是否可用
android:isolatedProcess="" //是否在单独进程中运行
android:procee="" //运行服务的进程
android:premission="" //权限
/>
前台服务
ANR:20s, 后台:10s
流程:构建Notification–>在service中调用startForeGround(1,Notification);
使用PendingIntent可以相应响应的点击意图
...
//点击通知后跳转MainActivity
Intent intent=new Intent(this,MainActivity);
PendingIntent pen=PendingIntent.getActivity(this,请求码,intent,标识符);
notifivation.setLatesetEventInfo(this,标题,内容,pen);
startForeground(1,notification);
其他
无法从广播找中绑定服务