0

I have two activities ActivityOne and ActivityTwo each one contains one Fragment

i did startActivityForResult(mIntent, Request_code) from the fragment of the first activity (ActivityOne) for calling the second activity (ActivityTwo), the problem is onActivityResult of the second activity has not being called?

Context
  • 1,873
  • 1
  • 20
  • 24
  • 2
    `onActivityResult` will be called in the first activity when the second activity has been completed, and not in the second activity itself. – almightyGOSU Dec 07 '14 at 15:02
  • 1
    onActivityResult of the second activity will be called if you start an activity (with startActivityForResult()) from the second activity – Rami Dec 07 '14 at 15:02
  • yes you're right but how i can call the onActivityResult of the second activity because this is the problem? – Context Dec 07 '14 at 15:09
  • I assume you are trying to pass something (e.g. data, object, etc) from ActivityOne to ActivityTwo? Maybe you can briefly explain what you're trying to achieve with ActivityOne & ActivityTwo. – almightyGOSU Dec 07 '14 at 15:13
  • yes but i want to work with requestCode and from this request code i can distinct which action i do and which data i receive because i have many action! – Context Dec 07 '14 at 15:19
  • Pass the request code using `public Intent putExtra (String name, int[] value)` in ActivityOne & use `public int getIntExtra (String name, int defaultValue)` in ActivityTwo? That's one way that I can think of. – almightyGOSU Dec 07 '14 at 15:23
  • Here, in this link, it is mentioned that this is the only way. http://stackoverflow.com/questions/19219926/android-request-code-in-oncreate – almightyGOSU Dec 07 '14 at 15:25

4 Answers4

0

As mentioned in the comment, onActivityResult will only be called in the activity (e.g. ActivityOne) that started some other activity (e.g. ActivityTwo) for a result, using startActivityForResult(...);

You can read up on this in the developer guide here

If, by any chance, you are trying to pass something from ActivityOne to ActivityTwo,
you can use putExtra(...) in ActivityOne & use getExtra(...) in ActivityTwo.

almightyGOSU
  • 3,731
  • 6
  • 31
  • 41
0

You have to call onActivityResult method of the fragment of first activity inside onActivityResult method of first Activity. In other words you have to delegate onActivityResult method form activity to fragment. onActivityResult of your second activity will be called only if you call startActivityResult from within your second activity.

michal.z
  • 2,025
  • 1
  • 15
  • 10
0

onActivityResult of your second activity will be called if u call startActivityResult from within your second activity.In your case the onActivityResult of the first activity will be called

archon92
  • 447
  • 3
  • 13
0

ActivityOne onActivityResult will call onCreate of ActivityTwo.

In ActivityTwo, when you call setResult(requestNo,returnIntent), this will call the onActivityResult of ActivityOne.