远程Service的显示 / 隐式启动
在进程间通信时,常会设计开启远程 Service 的情况。开启远程 Service 的方式有两种,一种时显示开启,一种是隐式开启。下面分别来看:
一、隐式开启
服务端:Service 所在 AndroidManifest.xml 中的配置如下,注意 exported = "true" ,为 true 才可被其他 App 访问,否则就只限于应用内。
<service
android:name=".BookManagerService"
android:exported="true">
<intent-filter>
<action android:name="com.sl.aidl"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
客户端:需要开启远程服务
Intent service = new Intent();
service.setAction("com.sl.aidl"); //service 的 action 值
service.setPackage("com.sl.binderservice"); //远程服务所在包名
//绑定服务
bindService(service, mConnection, Context.BIND_AUTO_CREATE);
//启动服务
startService(service);
二、显示开启
服务端:AndroidManifest.xml
<service android:name=".BookManagerService" android:exported="true"/>
客户端:
public static final String NAME_REMOTE_SERVICE = "com.sl.binderservice.BookManagerService" ;
public static final String PACKAGE_REMOTE_SERVICE = "com.sl.binderservice" ;
//启动服务
Intent startIntent = new Intent ();
ComponentName componentName = new ComponentName(PACKAGE_REMOTE_SERVICE ,NAME_REMOTE_SERVICE);
startIntent .setComponent (componentName );
startService( startIntent) ;
//绑定服务
Intent startIntent = new Intent ();
ComponentName componentName = new ComponentName(PACKAGE_REMOTE_SERVICE ,NAME_REMOTE_SERVICE);
startIntent .setComponent (componentName );
bindService( startIntent, mConnection, Context.BIND_AUTO_CREATE) ;
以上就是这两种开启方式。
远程Service的显示 / 隐式启动的更多相关文章
- ANdroid5.0不能隐式启动service,必须显示,解决办法,加服务端包名
Intent intent = new Intent(); intent.setAction("com.viaembedded.veonvif.RemoteService");// ...
- Intent显示启动与隐式启动
Android的Acitivity启动大致有两种方式:显式启动与隐式启动.下面分别介绍: 1.显示启动: 清单文件注册Activity <activity android:name=" ...
- Android隐式启动匹配:action,category,data
简介 Android开发中,Activity,Service 和 BroadcastReceiver 启动有两种方式,显示启动和隐式启动. 为方便下面描述,我以Activity启动为例. 显示启动便是 ...
- Android隐式启动Activity可能存在的坑
转载本专栏文章,请注明出处,尊重原创 .文章博客地址:道龙的博客 本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 本篇文章,对隐式启动Activity再做分析. 有些人可能会说了, ...
- 第一行代码阅读笔记----显示隐式Intent的基本用法
1.显示Intent意图明显,通过Intent启动另外一个活动,这是安卓中各组件进行交互的一种重要方式.一般用于启动活动,启动服务,发送广播等场景. 实现方法,这里我只说思路,实践还是要自己实操才能明 ...
- 显式启动Activity和隐式启动Activity
1.显式启动Intent intent = new Intent(this, class);startActivity(intent); 2.隐式启动AndroidManifest.xml中定义某个A ...
- Android-隐藏app图标以及隐式启动
隐藏APP桌面图标 <activity android:name=".LaunchActivity"> <intent-filter> <action ...
- Android-----Intent中通过startActivity(Intent intent )隐式启动新的Activity
显式Intent我已经简单使用过了,也介绍过概念,现在来说一说隐式Intent: 隐式Intent:就是只在Intent中设置要进行的动作,可以用setAction()和setData()来填入要执行 ...
- 隐式启动判断是否有匹配的Intent
一.PackageManager的resolveActivity public abstract ResolveInfo resolveActivity(Intent intent, int flag ...
随机推荐
- How to Get Text inside a Canvas using Webdriver or Protractor
https://stackoverflow.com/questions/43609429/how-to-get-text-inside-a-canvas-using-webdriver-or-prot ...
- asyncio 中给running 的loop 动态添加 Future Task
https://my.oschina.net/backbye/blog/1919486 asyncio 提供了两个给运行中的事件循环(loop) 添加 事件的方法 call_soon_threadsa ...
- select2 AJAX获取数据
页面效果: index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"& ...
- 观实验室PPT演讲有感
outline 一定要有 说话的语速要慢,压制住紧张的心情 提前一天发布PPT dont` argue with audience, especially professor and teachers ...
- android 导出apk
一个困扰了几个月的问题在今天得以解决,运动益智可能有点过,能让一个人思路清晰倒是真! 问题描述:本地调试运行及不加密导出apk运行正常,当加密生成apk安装后,从接口返回的数据总是空.尝试过各种配置, ...
- windows下常用的几个批处理脚本
1.windows下对比两个文件内容,有差异则执行一个任务: 适用场景:比如你的数据库备份结果的日志每天会形成一个文件,如下图,你可以通过此脚本检测到文件的变化,并执行发送告警邮件通知你数据库备份异常 ...
- Oracle分析函数简析
oracle的分析函数over(Partition by...) Sql代码 over(Partition by...) 一个超级牛皮的ORACLE特有函数. 最近工作中才接触到这个功能强大而灵活的函 ...
- 部署phpmyadmin登录不进去
Centos7.5 部署phpmyadmin登录不进去 问题:明明输对了账号和密码就是登录不进去,但是用ip就能登录 解决方法:换个域名 [root@web01 code]# vim /etc/ngi ...
- 类中函数前、后、参数加const
1.参数加const:int fun(const int a) a在函数里不可被修改 2.函数前加const:const int* const fun() 这种一般是返回的指针或者是引用,加const ...
- 给sublime设置格式化代码的快捷键
sublime中自建的有格式化按钮: Edit -> Line -> Reindent 只是sublime并没有给他赋予快捷键,所以只需加上快捷键即可 Preference -& ...