0

I'm developing an app that should be able to get invoked by other apps and send back a result. I tried using intents with startActivityForResult(), but I faced two problems: First, with launchMode singleTop, the app is initialized again on every invocation. Because the calling apps will invoke my app a lot and the initialization takes some time because of authentication, this is not an option. So I tried launchmode singleTask. But I found out that startActivityForResult() will not return results to another task.

So now the question: How can an app invoke an already initialized activity in another app, get back a result, and keep the invoked activity initialized. For example: A invokes B. Do some stuff in B. Focus and results return to A. B stays initialized, so it can later be invoked by A again.

After reading lots of documentation I came up with the following possible solutions:

  • A invokes B. B invokes A again with a result in the intent extra. (Somehow state of A should be saved)
  • A invokes B. B sends a broadcast to A. Focus returns to A and A receives result in a BroadcastReceiver.
  • A invokes B. result of B is stored in a content provider in B. Focus returns to A. A requests result from content provider in B.
  • Or using launchmode singleTop and startActivityForResult() and in some way save state of B after the result is sent back to A?

Which solution is best/will work? Or are there any other/better solutions?

Sven
  • 1
  • 1
  • 1
    Are you writing both A and B? If not, why will the authors of various A apps bother with all of this? If you are writing both A and B, why are they separate apps in the first place? If they are this tightly coupled ("the calling apps will invoke my app a lot"), it sounds like they should be just one app, not two (or more). – CommonsWare Feb 02 '15 at 16:06
  • I am writing B, two other teams are writing A's and in the future I will write other A's as well. It's not one app, because it gets very big and multiple teams are working in the same codebase then. Plus I think it's better to maintain this way.. – Sven Feb 03 '15 at 07:34

0 Answers0