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.

有帮助吗?

解决方案

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)

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top