2

I have two different application called App A and App B.

  • App A : ActivityA with launch mode -> "singleTask"
  • App B : ActivityB with launch mode -> "singleInstance"

Steps:

  1. Open App A which will open ActivityA, ActivityStack : ActivityA
  2. Starting App B with startActivityForResult(), ActivityStack : ActivityA > ActivityB
  3. Open ActivityA via Intent from Activity B , ActivityStack : ActivityA > ActivityB > ActivityA

As you can see the activity stack, It creates new instance of the Activity A instead of returning to the same instance of the ActivityA by calling onNewIntent() method.

I am not sure, is this because of Activity started for result.? Please help to provide proper solution in this scenario. Thank you.

VP4Android
  • 576
  • 4
  • 17
  • I think activity never has any instance. It is managed by the android lifecycle. – Pranav P Dec 03 '19 at 04:27
  • try to add this intent filter in your ActivityB intent "flag_activity_reorder_to_front" – Chirag Rayani Dec 03 '19 at 04:53
  • I've answered your question. But what are you trying to do? I'm sure there are simpler ways of doing this. – David Wasser Dec 05 '19 at 13:52
  • @David Wasser: When i send Open ActivityA via Intent from Activity B, i want the same ActivityA instance(which started ActivityB) to be called via onNewIntent() instead of creating new instance. Could you help me with that. – VP4Android Dec 05 '19 at 18:09
  • you could have A call B using `startActivityForResult()`. This won't work if you are using special launch modes (singleInstance or singleTask). Why are you using special launch modes? – David Wasser Dec 05 '19 at 18:51

1 Answers1

2

You cannot start a singleTask Activity using startActivityForResult(). If you launch an Activity and expect a result returned, then the target Activity must be launched in the same task. Due to this, Android is ignoring the singleTask launch mode when you call startActivityForResult().

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • Thanks @David Wasser. Make sense. If you have started an Activity for result then android automatically ignore the "singleTask". – VP4Android Dec 05 '19 at 17:32