I created three Activities in an android app: MainActivity, SecondActivity, ThirdActivity and log the onCreate@taskId event of those Activities.
The launch mode of SecondActivity is set to singleInstance.
Then I put two buttons in MainActivity.
button1 startActivity(SecondActivity).
button2 startActivityForResult(SecondActivity).
button3 startActivity(ThirdActivity).
After click button1 -> click button3 I got the following log, which is as I expected:
MainActivity onCreat@xxx0
SecondActivity onCreate@xxx1 // second activity is expected in a new task
ThirActivity onCreate@xxx0 // third
But, click button2 -> click button3:
MainActivity onCreat@xxx0
SecondActivity onCreate@xxx0 // it seems that startActivityForResult will make singleInstance activity not work
ThirdActivity onCreate@xxx1 // Here is the weird thing, the ThirdActivity is created on a new task!
Can someone explain this?
Here is the repo singleInstanceTest for reproducing.