19

I am developing two applications names A and B.

Application A as activity named MainActivity, service called UpdateService, BroadcastReciever called UpdateReceiver.

Application B as activity named TestActivity, service called DoService, BroadcastReciever called DoReceiver.

In my application B, I want to access few methods and code from MainActivity which is in Application A.

In this way, I need full control of Application A code to access it in my application B.

How can I achieve it?

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
user1810931
  • 638
  • 2
  • 11
  • 33

2 Answers2

24

You cannot directly access methods of Activity in different app.

Broadcast would work but if you want more control (i.e. invoke remote methods) consider binding to a remote service in the other app or use Messenger and handler to communicate.

Here is a short tutorial on inter-app communication

iTech
  • 18,192
  • 4
  • 57
  • 80
  • 2
    @iTech The inter-app communication tutorial link seems to be broken, I get a Not Found, any ideas? – avenet Jan 09 '14 at 18:39
  • Interesting!! I came here after a long time it was posted the link in the answer is working with [WayBackMachine](https://web.archive.org/web/20130731024012/http://code.google.com/p/openmobster/wiki/InterAppCommunication) – Pratik Jamariya Apr 03 '18 at 17:54
  • Be aware that if your app targets API level 26 or greater, implicit broadcasts will not work with the exception of a handful of system broadcasts. Your own broadcast will not get past process boundaries unless they are "explicit" – Leo Jun 10 '19 at 02:56
4

You can't share methods and code segments between different applications, but you can use intents to send data bundles back and forth, check this similar question:

android communication between two applications

Community
  • 1
  • 1
Badr Ghatasheh
  • 968
  • 2
  • 7
  • 19