How can Fragment.getActivity () return null in Fragment.onPrepareOptionsMenu ()?

How does it possibly Fragment.getActivity()

return null in Fragment.onPrepareOptionsMenu()

?

I found a rare error posted by users.

@Override
void onPrepareOptionsMenu(Menu menu) {
    // ...
    getActivity(); // <-- is Null
    // ...
}

      

If a Fragment

is decoupled from the activity, how can it participate in shaping the content of the action bar?

+3


source to share





All Articles