0

My app show activity(1) .when you press button ,app open fragment .After that , fragment send data to activity (2) and open activity (2) -that works well- . Finally ,activity(2) edit the data and send it to activity(1) -here is problem- .

I have tried many ways but it doesn't work

2 Answers2

2

When you are working with complex screens like multiple fragments and activities, I would recommend you to just use an event-driven library, like:


It's going to let you transform this:

No EventBus

into this:

With EventBus


Check this post for a detailed explanation about the use cases of these libraries.

Evin1_
  • 12,292
  • 9
  • 45
  • 47
  • 1
    I strongly support EventBus. It's awesome. – Vucko Jun 11 '16 at 17:52
  • @Evin1_ I don't change any thing in mainefast or gradle except add compile . I use otto . My problem is I can't use any method inside subscribber method . Even I can't write getmsg.message = my_varible ; I use this way https://www.youtube.com/watch?v=lVqBmGK3VuA – m.developer Jun 16 '16 at 19:35
0

May be like this;

In fragment:

Intent i = new Intent(getContext(), Activity2.class);
i.putExtra("data", data);
getActivity().startActivityForResult(i, REQUEST_CODE);

In activity(2):

Intent resultIntent = new Intent();
resultIntent.putExtra("data", data);
setResult(Activity.RESULT_OK, resultIntent);
finish();

And in activity(1):

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (requestCode == REQUEST_CODE) {
     // Make sure the request was successful
         if (resultCode == Acitivity.RESULT_OK) {
             String stringData = data.getExtras().getString("data"); 
             // Data can be string, int etc. or serializable
             // YourObject object = (YourObject) data.getExtras().getSerializable("data");
        }
    }
}
C.Ozyurt
  • 21
  • 1
  • 7