Search code examples
androidandroid-intentandroid-activityonactivityresult

onActivityResult not working with android:launchMode="singleTask"


I call Activity-B from Activity-A where there is need for android:launchMode="singleTask" in Activity-B and onActivityResult in Activity-A.

I am facing a problem with onActivityResult in Activity-A when Activity-B is finished onActivityResult in Activity-A not execute.


Solution

  • Since Activity-B is a singleTask I am afraid that you can not return a resulft from it, as the documentations state:

    For example, if the activity you are launching uses the singleTask launch mode, it will not run in your task and thus you will immediately receive a cancel result.

    So you can not return a result from it, and there is no way to get around it if you need Activity-B to be singleTask.

    Since you have developed Activity-B by yourself you can make some little changes and have it to send a broadcast with the result and Activity-A can then list to this broadcast and get the result.