When fragment is detached from activity, getActivity() return null, so getActivity().getApplication() produce NPE. So we should check whether the fragment is attached to activity.

This commit is contained in:
Alexander Sytnyk 2017-07-10 13:11:08 +03:00
parent 9e044b5449
commit 7ea02dcdae

View file

@ -18,8 +18,11 @@ public class BaseOsmAndFragment extends Fragment {
private IconsCache iconsCache; private IconsCache iconsCache;
protected OsmandApplication getMyApplication() { protected OsmandApplication getMyApplication() {
if (isAdded()) {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
return null;
}
protected OsmandActionBarActivity getMyActivity() { protected OsmandActionBarActivity getMyActivity() {
return (OsmandActionBarActivity) getActivity(); return (OsmandActionBarActivity) getActivity();