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(context);
mContext = context;
}
@Override
public void onDetach() {
super.onDetach();
mContext = null;
}
Edited, since onAttach(Activity)
is depreciated & now onAttach(Context)
is being used