新しい Google Maps API からの SuportMapFragment を埋め込む Fragment に問題があります。私のフラグメントが作成されるとAsyncTask
、メソッドの最初にいくつかのデータがフェッチされますonResume
。これが発生している間、MapFragment は画面外に残り、代わりにプログレス バーが表示されます。
AsyncTask
完了したらonGlobalLayout
mapViewのイベントに登録します。次に、フラグメントを表示すると、マップ ビューが表示され、レイアウトされます。onGlobalLayout
がトリガーされ、アニメーションが開始されます。
AsyncTask
これは、データ収集の操作を最適化してほぼ瞬時に完了するまで、かなり長い間うまくいきました。現在、アプリは起動時にクラッシュすることが多く、デバッグよりもリリースでより頻繁にクラッシュします。
例外は次のとおりです。
マップ サイズは 0 であってはなりません。最も可能性が高いのは、マップ ビューのレイアウトがまだ行われていないことです。
どんな洞察も大歓迎です。
参考までに:これはクラッシュの原因と思われるコードです:
// Hide status UI
this.progressBar.setVisibility(View.INVISIBLE);
this.statusTextView.setVisibility(View.INVISIBLE);
// Update state
this.uraDataDownloadFinished = true;
// Schedule map translation to occur when layout is complete
final View mapView = this.mapFragment.getView();
if (mapView.getViewTreeObserver().isAlive())
{
mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener()
{
@SuppressWarnings("deprecation")
@SuppressLint("NewApi") // We check which build version we are using.
@Override
public void onGlobalLayout()
{
Log.d(TAG, "onGlobalLayout()");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
{
mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
else
{
mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
// here we crash
this.map.animateCamera(
CameraUpdateFactory.newLatLngBounds(
LatLngBounds.builder()
.include(topLeft)
.include(topRight)
.include(bottomLeft)
.include(bottomRight)
.build(),
0),
durationMs,
null);
}
});
}
// Show map (which will eventually trigger onGlobalLayout)
this.getFragmentManager().beginTransaction().show(this.mapFragment).commit();
this.mapFragment.getMap().setOnCameraChangeListener(this);
どうもありがとう!