On changing tab from 1 to another. TabStackInterface.onTabFragmentPresented() returns getActivity()==null;
On changing tab from 1 to another. TabStackInterface.onTabFragmentPresented() returns getActivity()==null;
Hello Sandeep and thank you for your feedback.
You are right, getActivity always returns null in this callback :/
I'm not sure I can fix this, as this is how the lib and android work together:
- fragments are restored from TabStacker, and callbacks are called on ALL fragments of the new tab
- android makes asynchronous attachement later (then getActivity returns a valid activity) so it is too late, + the attachement is not done on all fragments, but only those supposed to be visible.
I will continue to investigate but for the moment I have no fix or workaround.
I can just suggest to move your code in onAttach() so that you are sure that the Activity is valid at this moment, but it won't be called on every fragment.
@Override
public void onAttach(Context context) {
Activity activity = getActivity();
// do something with the Activity
super.onAttach(context);
}
Arnaud.
Thank you @smart-fun for your quick response. Let this issue open for now so that subscribers can get the information
Did you manage to use TabStacker even if getActivity() returns null when the callbacks are called?