0

I am a bit of a noob attempting to pass data between a fragment (living inside a tab layout) and the activity that runs the fragment.

I have found a solution here, but I am unable to call the parent activity from the fragment.

Send data from activity to fragment in Android

Looking up multiple answers, they all say the same thing

CALL getActivity()!!

Call parent's activity from a fragment

It doesn't exist. I am using the Android.Support.V4.App.Fragment.

I can access a property this.Activity, but it's calling a random FragmentActivity when this is being hosted on an AppCompatActivity.

How can I access my hosting AppCompatActivity from the support Fragment?

Ryan D.
  • 57
  • 6
  • 1
    `AppCompatActivity` extends `FragmentActivity`. What makes you think the activity that is being returned isn't your actual activity? – ianhanniballake Oct 21 '21 at 21:10
  • Confusion over how xamarin works. My AppCompatActivity is called NewActivity. When I called (NewActivity)this.Activity.setOnBundleSelected() it couldn't access the setOnBundleSelected() method despite being public. However when I call it like (this.Activity as NewActivity).setOnBundleSelected() I can now use it, so maybe I was just confused. Thank you. – Ryan D. Oct 22 '21 at 12:52

1 Answers1

0

I would suggest using viewmodels to pass data between activities and fragments

MikkelT
  • 633
  • 1
  • 10
  • 16
  • Thank you, is there any available resources on viewmodels where I could learn more that you could recommend. It's very frustrating trying to figure anything out because I spend days reading, try to implement it, and find out it's years obsolete. I feel like I keep learning variations of the same thing 5 times and I still don't know the right way. – Ryan D. Oct 22 '21 at 12:54