gpt4 book ai didi

java - 将数据从 Activity 传递到 android 中位于不同应用程序中的服务

转载 作者:太空狗 更新时间:2023-10-29 14:23:01 25 4
gpt4 key购买 nike

我知道您可以在传递数据时使用 Intent。我的问题是,我想从我的 Activity 调用另一个应用程序中的服务。

这是示例场景...

APP1:LoginActivity --> 传递参数给APP2,调用APP2:VerifyLogin --> 结果返回给APP1:LoginActivity

有办法吗?

最佳答案

1) 如果您拥有这两个应用程序,最好从 APP1 本身调用 APP2 的服务(即在 APP1 而不是 APP2 中定义服务)。

但是如果有两个应用程序之间需要通信的情况,您可以实现不同的策略来满足它们,如下所示。

2) 利用广播接收器:

在APP2中注册一个Broadcast Receiver,从APP1发送一个广播消息,带上需要的参数,同样从APP2到APP1使用Broadcast Receiver机制进行通信。

3) 利用Android Interface Definition Language (AIDL) ,

Google 文档 说:

It allows you to define the programming interface that both the client and service agree upon in order to communicate with each other using interprocess communication (IPC).

我认为这将使您能够通过定义一些通信协议(protocol)在两个应用程序之间进行通信。

示例:这是一个nice TUTORIAL这将帮助您了解它的实际工作原理。

希望这能给您一些解决问题的提示。

关于java - 将数据从 Activity 传递到 android 中位于不同应用程序中的服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15016377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com