I can easily communicate between two fragment
s of an activity by callback interface
. Following that way, I have implemented an interface in ParentFragment
to communicate.
But in case of activity, I was using -
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mCallback = (OnHeadlineSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
And in current case, I am using mCallback = (OnHeadlineSelectedListener) getParentFragment();
instead of mCallback = (OnHeadlineSelectedListener) activity;
. Everything is working well. Is this approach okay? Or should I do it into another thread instead onAttach()
?