Domanda

It sounds me a confusing Question. What is the Activity Object in onAttach method of a fragment which is nested inside a parent Fragment?

I know I can communicate to the parent fragment by using getParentFragment() method.But I want to know if this activity object in the onAttach returns the FragmentActivity instance or not, so as to have a direct communication (by using interface callback) from a nested fragment to the FragmentActivity.

Sorry for my bad English. I tried my best to convey my thoughts.

È stato utile?

Soluzione

Yes, the Activity object is your FragmentActivity. Check the docs here: http://developer.android.com/reference/android/app/Fragment.html#onAttach(android.app.Activity)

You can also get the activity by using getActivity() anywhere in your fragment (but be aware it only works after onActivityCreated has been called)

Altri suggerimenti

Yes it is the FragmentActivity that hosts the Fragment (directly or nested in another Fragment). There is more information about communicating with the parent FragmentActivity here.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top