Added a null check on `getActivity()`