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?