我创建了一个使用com.google.android.gms.maps.MapView
在地图上显示一些图钉的应用。该应用程序在大多数设备上均可正常运行,但OnePlus 6(Andorid 9)和Google Pixel 2(Andorid Q)的行为有些奇怪。我已经在情侣OnePlus 6(与Andorid 9相同)上对其进行了测试,并且工作正常,因此问题仅在某些设备上出现。
问题:带有地图的Activity
在无限循环中重新启动,没有崩溃。
我与地图逻辑相关的代码是:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivityBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
//...
onInitMap(savedInstanceState);
}
private void onInitMap(Bundle savedInstanceState) {
mapView.onCreate(savedInstanceState);
// needed to get the map to display immediately
mapView.onResume();
try {
MapsInitializer.initialize(MainActivity.this);
} catch (Exception e) {
e.printStackTrace();
}
mapView.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
//listen camera moved and stop - when stop then get http data for coordonates and range
mGoogleMap.setOnCameraIdleListener(MapActivity.this);
mGoogleMap.setOnMapClickListener(MapActivity.this);
//setup cluster logic
mClusterManager = new ClusterManager<SalonMarkerMetaDataObj>(this, mGoogleMap);
mSalonMarkerRenderer = new SalonMarkerRenderer(MapActivity.this, mGoogleMap, mClusterManager);
mClusterManager.setRenderer(mSalonMarkerRenderer);
mGoogleMap.setOnMarkerClickListener(mClusterManager);
mGoogleMap.setOnInfoWindowClickListener(mClusterManager);
mClusterManager.setOnClusterClickListener(this);
mClusterManager.setOnClusterItemClickListener(this);
}