1

I have an Activity (C) which can be opened (for result) from more than one other Activity (A and B). Sometimes it goes [A -> B -> C] and sometimes it just goes [A -> C].

I want the scenario [A -> B -> C] to make C return the result to B.

And I want scenario [A -> C] to make C return the result to A.

In both cases Activity C is supposed to do the same thing, but how do I know which Activity type I should use for my Intent when preparing the result (aka how do I know which Activity opened C)?

This os probably rather trivial but I'm a Xamarin noob so bear with me.

/Aidal

Aidal
  • 799
  • 4
  • 8
  • 33
  • Possible duplicate of [Accessing instance of the parent activity?](http://stackoverflow.com/questions/4944651/accessing-instance-of-the-parent-activity) – SushiHangover Nov 03 '16 at 14:43
  • Not completely since the other post only has 2 avtivities, but none the less I got pointed in the right direction by it. It seem that this will do the trick: this.CallingActivity.ClassName.Split('.')[1] = . Thanks! – Aidal Nov 03 '16 at 15:00
  • You can add extra data to your Intent and access it in the "child" Activity.: `intent.PutExtra(....);` and react to it accordingly to avoid hardcoding ClassName checks in the "child" Activity to avoid the "code smell". – SushiHangover Nov 03 '16 at 15:11
  • Of cause, I dunno why I didn't think of that because I already use that feature to pass data :D – Aidal Nov 03 '16 at 15:31
  • 1
    In Android (native) you would use `startActivityForResult()`. It looks like Xamarin supports this as well. See https://developer.xamarin.com/recipes/android/fundamentals/activity/start_activity_for_result/ – David Wasser Nov 03 '16 at 20:42

0 Answers0