Data transfer with a few actions

1- my first activity (main) 2- this is my second activity 3 - this is my third action.

I want to run 2 of 1, and then form 2 to run 3, and then from 3 I take the data and return it to 1. I hope you guys understand.

Here is my code:

Running 2 forms of 1 liek is:

            Intent intent = new Intent(getApplicationContext(),MessageBox.class);
             intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
            startActivityForResult(intent,5);               

And then do 3 of 2, like this:

                Intent intent = new Intent(getApplicationContext(),ImageReceiver.class);

                startActivityForResult(intent,5);

And then in 3 I have something like this:

          setResult(10);
          finish();

So, I set the result, so in 2, to get this result, I:

        if(requestCode==5)
        {
            if(resultCode==10)
            {

                Intent intent = new Intent(getApplicationContext(),MainActivity.class);

                setResult(5,intent);
                finish();
            }
        }

And then at 1 I got:

     if(requestCode==5)
     {
         if(resultCode==5)
         {
             //here i am taking data from 3
         }
     }

The problem is that I cannot open 2 coz in logcat, I get:

04-23 22: 13: 15.579: E / AndroidRuntime (15313): android.util.AndroidRuntimeException: FORWARD_RESULT_FLAG is used, also requesting the result

And I really don’t understand what to do. Take a look at this code.

+4
2

2 1:

Intent intent = new Intent(getApplicationContext(), MessageBox.class);
intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
startActivityForResult(intent,5);

, . FLAG_ACTIVITY_FORWARD_RESULT startActivityForResult() .

, 1 3, 2 1 :

Intent intent = new Intent(getApplicationContext(), MessageBox.class);
startActivityForResult(intent, 5);

3 2 :

Intent intent = new Intent(getApplicationContext(), ImageReceiver.class);
intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
startActivity(intent);
finish();

Android, 3 (ImageReceiver) , 2 (MessageBox). 3 , onActivityResult() 1 , 3.

+11

1

intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);

2

Intent intent = new Intent(getApplicationContext(),MainActivity.class);

.

+1

Source: https://habr.com/ru/post/1537780/


All Articles