mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Prevent crash caused child fragment is actually null by checking if it is attached or not.
This commit is contained in:
parent
d0556419f7
commit
f4321d0541
2 changed files with 15 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.free.nrw.commons.nearby.mvp.fragments;
|
package fr.free.nrw.commons.nearby.mvp.fragments;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
@ -104,6 +105,12 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
((NearbyParentFragment)getParentFragment()).childMapFragmentAttached();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapView setupMapView(Bundle savedInstanceState) {
|
public MapView setupMapView(Bundle savedInstanceState) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,14 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
resumeFragment();
|
resumeFragment();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thanks to this method we make sure NearbyMapFragment is ready and attached. So that we can
|
||||||
|
* prevent NPE caused by null child fragment. This method is called from child fragment when
|
||||||
|
* it is attached.
|
||||||
|
*/
|
||||||
|
public void childMapFragmentAttached() {
|
||||||
nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter(this, nearbyMapFragment);
|
nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter(this, nearbyMapFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue