栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

【安卓】启动Service

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【安卓】启动Service

启动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:用于远程操作对象的一个基本接口

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/727101.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号