The best to get rid of this is to keep activity reference when onAttach is called and use the activity reference wherever needed, for e.g.
@Override
public void onAttach(Context context) {
super.onAttach(activity);
mContext = context;
}
@Override
public void onDetach() {
super.onDetach();
mContext = null;
}