When viewing a fragment in ViewPager, the message should be displayed to the user. Currently calling:
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
MessageUtility.displayMessage(getContext());
}
}
MessageUtility.displayMessage() opens a message dialog box.
Contextrequired to display the message. However, the fragment cannot be attached to a point in time setUserVisibleHint(). So it Contextwill be null, though isVisiableToUser == true.
Verification isVisibleToUser && isAttached()works in theory, but setUserVisibleHint()does not occur after isAttached() == true.
Is there any way to allow the call displayMessage()until attached Fragment?
source
share