If you have a need, you’ve come to the right place:

MainActivity contains FragmentA and FragmentB, and FragmentA has buttons in it that jump to ActivityB, and then the requirement is to return directly to FragmentB when it returns from ActivityB.

The first is the FragmentA B, which passes the request code with the value 1 inside the Button click event. The code is as follows:




In the FragmentA

👌, go to ActivityB and set the result code in the Button click event




In the ActivityB

All right. After ActivityB finishes (), we ask it to go to FragmentB. The onActivityResult method is used. Override this method in FragmentA, then determine if the response and request code match, and if so, start FragmentB with something (or write a method in MainActivity). The code is as follows:




In the FragmentA

Ok. The general idea is: Get in and get out.