Passing data though multiple activities

后端 未结 2 1185
轻奢々
轻奢々 2020-12-31 23:05

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

I want to run 2 from 1 and then form 2 run 3 , and then from 3 i am taking data and r

相关标签:
2条回答
  • 2020-12-31 23:27

    You cannot do this when starting 2 from 1:

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

    This will throw the exception you are getting. You cannot use FLAG_ACTIVITY_FORWARD_RESULT and startActivityForResult() together.

    If you want 1 to get the result from 3, then you need to start 2 from 1 like this:

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

    and then start 3 from 2 like this:

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

    This tells Android that activity 3 (ImageReceiver) should forward its result back to the activity that called activity 2 (MessageBox). When activity 3 sets its result and finishes, onActivityResult() in activity 1 will be called with the result data sent from activity 3.

    0 讨论(0)
  • 2020-12-31 23:46

    comment out this line in activity 1

    intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    

    and this line in activity 2

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

    You should be all set.

    0 讨论(0)
提交回复
热议问题