onAttach(Activity activity) what is this activity in a fragment inside another fragment

StackOverflow https://stackoverflow.com/questions/23661165

Вопрос

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