远程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 ...
随机推荐
- spring总结之一(spring开发步骤、bean对象的管理、bean生命周期)
###spring 1.概念:开源,轻量级,简化开发的企业级框架. 开源:免费,发展快. 轻量级:占内存小. 简化开发:通用的功能封装,提高程序员的开发效率.--------------------- ...
- Mysql安装错误:Install/Remove of the Service Denied!解决办法
Mysql安装错误:Install/Remove of the Service Denied!解决办法 在windos 的cmd下安装mysql 在mysql的bin目录下面执行: mysqld -- ...
- eclipse maven Errors while generating javadoc on java8
With JDK 8, we are unable to get Javadoc unless your tool meets the standards of doclint. Some of it ...
- 4、pandas的数据筛选之isin和str.contains函数
DataFrame列表: 以>,<,==,>=,<=来进行选择(“等于”一定是用‘==’,如果用‘=’就不是判断大小了): 使用 &(且) 和 |(或) 时每个条件都要 ...
- Java类型信息
一.引言 最近在阅读<Java编程思想>,学习一下java类型信息,现在做一下总结.Java如何让我们在运行时识别对象和类的信息的.主要有两种方式:一种是传统的“RTTI”,它假定我们在编 ...
- svg动态添加小人
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- CEF 文件下载
转载:https://blog.csdn.net/liuyan20092009/article/details/53819473?locationNum=6&fps=1 转载:https:// ...
- 如何在servlet中获取spring创建的bean
package com.yxf.controller; import java.io.IOException; import javax.servlet.ServletException; impor ...
- Python3 tkinter基础 Entry get 点击按钮 将输入框中文字输出到控制台
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 list count 查询指定元素在列表中出现了多少次
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...