You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
Using Mapbox Android SDK 5.1.2. I've extended SupportMapFragment. Originally I was calling getMapAsync in onCreate:
@OverridepublicvoidonCreate(@NullablefinalBundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true); // this is relevantif(savedInstanceState == null) {
getMapAsync(newOnMapReadyCallback() {
@OverridepublicvoidonMapReady(finalMapboxMapmap) {
// set up map
}
});
}
}
The problem was that onMapReady was sometimes being called before the fragment's onCreateOptionsMenu, resulting in an NPE when I tried to access a menu item while setting up the map. So I tried posting the call to getMapAsync. When I do this, onMapReady is never called.
privatefinalHandlermHandler = newHandler(Looper.getMainLooper());
@OverridepublicvoidonCreate(@NullablefinalBundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true); // this is relevantif(savedInstanceState == null) {
mHandler.post(newRunnable() {
publicvoidrun() {
getMapAsync(newOnMapReadyCallback() {
@OverridepublicvoidonMapReady(finalMapboxMapmap) {
// set up map
}
});
}
});
}
}
So I tried posting from inside onMapReady. When I do this, everything works as expected.
privatefinalHandlermHandler = newHandler(Looper.getMainLooper());
@OverridepublicvoidonCreate(@NullablefinalBundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true); // this is relevantif(savedInstanceState == null) {
getMapAsync(newOnMapReadyCallback() {
@OverridepublicvoidonMapReady(finalMapboxMapmap) {
mHandler.post(newRunnable() {
publicvoidrun() {
// set up map
}
});
}
});
}
}
When checking for duplicate issues, I ran across #9136. I wonder if the fix for that created this.
The text was updated successfully, but these errors were encountered:
Thank you for the report, will look into reproducing this. fwiw if you want to add additional logic I would rather advice not extending SupportMapFragment but extending SupportFragment instead and copying over the SupportMapFragment implementation.
re. #9136, the PR fixing that issue hasn't been released yet.
I have added the related milestone to the ticket to reflect it.
Using Mapbox Android SDK 5.1.2. I've extended
SupportMapFragment
. Originally I was callinggetMapAsync
inonCreate
:The problem was that
onMapReady
was sometimes being called before the fragment'sonCreateOptionsMenu
, resulting in an NPE when I tried to access a menu item while setting up the map. So I tried posting the call togetMapAsync
. When I do this,onMapReady
is never called.So I tried posting from inside
onMapReady
. When I do this, everything works as expected.When checking for duplicate issues, I ran across #9136. I wonder if the fix for that created this.
The text was updated successfully, but these errors were encountered: