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,7 +18,10 @@ public class BaseOsmAndFragment extends Fragment {
private IconsCache iconsCache; private IconsCache iconsCache;
protected OsmandApplication getMyApplication() { protected OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication(); if (isAdded()) {
return (OsmandApplication) getActivity().getApplication();
}
return null;
} }
protected OsmandActionBarActivity getMyActivity() { protected OsmandActionBarActivity getMyActivity() {