there is activit And in it I execute startForResult activit B, then in the ActivityResult I process the result, from activi A. I don’t understand how to perform the last operation. code below is Activate A

public void startForResult(int requestCode) { if (requestCode==1) { //do something } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if( requestCode == xx ) { //do something } } 

then the fragment starts and it activates C. in it. I tried to use rx, create an Observable and subscribe to it when we get the result, but it did not go. Tell me what other options are there?

  • Why did you delete the question ? .stackoverflow.com /questions/ 573039 / ? So that no one but you will find a solution to this problem? How selfish. - Vladyslav Matviienko
  • Then you need to delete 75% of your questions - Vladyslav Matviienko
  • Well, this is your logic ... - Vladyslav Matviienko

3 answers 3

You need

  1. Launch C actions also via startActivityForResult .
  2. Further, after running B from C and returning the result to B onActivityResult will be onActivityResult to C
  3. In it, you can already set the result via setResult() for activating C , close it through finish()
  4. And after that get the result in the onActivityResult call in A

    With such a complex interaction, it is wiser to use a data bus, such as an EventBus , so communication between components will be much simpler, linear and reliable.

    reactive programming in solving such a problem is somewhat redundant and makes sense only if the entire project is built on its principles.

      Throwing from C to A. Do you think this is a good code?

      If you are doing this now, in the future you will decide to generally throw from Z to A. And this is fraught with the fact that, depending on the severity of the Activit or fragments, while you create, say, C. then A may just go away, because there may not be enough memory.

      In this case, it may be so. In any case, it is reasonable to launch a new Activation A from C. And transmit all the necessary data via Intent. And all other activations close. To avoid a memory leak