使用意图作为消息传递的一种形式 [英] Using Intents as a form of message passing

查看:117
本文介绍了使用意图作为消息传递的一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么缺点,使用意图的消息的形式,我控制两个应用程序之间传递?

Are there any drawbacks to using intents as a form of message passing between two apps that I control?

我将永远在设备上存在在一起的两个的apk。而且,我想用明确的意图来传递消息来回,而不是创建和管理两个独立的服务。使用明确的意图似乎只是比服务更容易管理的办法。

I have two apks which will always exist on the device together. And, I'd like to use explicit intents to pass messages back and forth as opposed to creating and managing two separate services. Using explicit intents just seems like an easier to manage approach than services.

推荐答案

应用程序之间的通信可以公开某些富人,但如果你真的需要做这样一来,你只能自定义您的应用程序将有知识的权限。然后你可以使用 BroadcasrReceiver 来交换信息安全地使用自定义权限。

Communication between applications can expose certain rich, but if you really need to do this way, you can only customizing permissions that your applications will have knowledge. Then you can use BroadcasrReceiver to exchange messages securely using custom permissions.

定义他们的许可:

<permission android:name="com.yourapp.PERMISSION"
    android:protectionLevel="signature"
        android:label="@string/permission_label"
        android:description="@string/permission_desc">
</permission>

通过设置

<receiver android:name=".MyReceiver"
    android:permission="com.yourapp.PERMISSION">
    <intent-filter>
        <action android:name="com.yourapp.ACTION" />
    </intent-filter>
</receiver>

除了这些权限,你还可以设置他们自己的购买活动服务的ContentProvider

编辑

安卓进程间通信),在 AIDL ( Android的接口定义语言)。

AIDL时特别有用不同的应用程序需要   它们之间的通信通过交换信息   定义良好的接口,支持多线程。不同的是使用   斜挎带绑定服务与AIDL,你需要创建   一份文件。 AIDL包含集成接口的声明,   这有助于客户端应用程序知道哪个操作是   可用以及它们各自的观点和回报。

AIDL is particularly useful when different applications need to communicate among themselves to exchange information through a well-defined interface with support for multithreading. Unlike the use of Messenger with Bound Services with AIDL you are required to create a file. AIDL containing the declaration of the integration interface, which helps the client applications to know which operations are available as well as their respective arguments and returns.

这篇关于使用意图作为消息传递的一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆