发送广播从一个应用程序到另一个

发送广播从一个应用程序到另一个

问题描述:

我目前在市场上的应用程序2,我们姑且称之为一个APP和APP湾

I currently have 2 apps in the market, let's call them app a and app b.

当某个功能在应用程序执行时,我需要一些东西来触发应用程序中的一个事件,即使一个应用程序当前未运行。我假设应用程序B.将发送广播消息到应用程序中的应用程序和一个需要的广播接收器,但我不知道如何可以做到这一点,如果是可以做到的。

When a certain function is executed in app, I need something to trigger an event in app a, even if app a isn't currently running. I assume app B would send a broadcast message to app a and app a would need a broadcast receiver but I am not sure how this can be done, if it can be done.

任何帮助将是很大的AP preciated,谢谢

Any help would be greatly appreciated, thanks

基本上有两种方式AFAIK:

There are basically two ways afaik:

  • Broadcast Receiver and using the sendBroadcast method on the sender side

或使用意图:

  • 您可以使用startActivity(意向),甚至与其他应用程序,但是这会带来应用到前台,而不是做工作的背景。

使用意图,如果调用应用程序应dissappear和被叫的应用程序应该在前台,并使用广播,如果你只是想通过另一个应用程序执行的后台任务

Use intents if the calling app should dissappear and the called app should be in foreground and use broadcasts if you just want a background task performed by another app