That's correct, you could also use:
getActivity().getApplicationContext();
which is the context for the entire application and not specific to that particular Activity
.
As a side note, if it happens to you to get some weird crashes, specially when you press quickly the back button removing all the fragment in your back stack, it may be that getActivity()
is returning null.