1

메소드에 프로그래밍 방식으로 추가 된 SupportMapFragment가 getChildFragmentManager()입니다.Android : Google Maps API v2 하위 정리 방법 SupportMapFragment

활동이 닫힌 후에 앱을 다시 열면 앱에 마커가없는 이전 자식 SupportMapFragment이 렌더링 된 것으로 보입니다. 이전 하위 조각은 상호 작용할 수 없습니다.

이 수명주기 문제를 SupportMapFragment으로 수정하려면 어떻게해야합니까? 특정 분리 방법 또는 그와 비슷한 것을 부를 필요가 있습니까?

답변

1

문제는 내 자식 조각을 처리하는 방식과 관련이 있습니다.

부모 조각이 onCreate을 호출 할 때마다 자식 조각이 재생성됩니다.

나는 내 아이의 조각을 처리하기 위해 다음과 같은했지만 더 나은 방법이있을 수있다 :

private static final String TAG_FRAGMENT_MAP = "TagFragmentMap"; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    // ... 
    if (savedInstanceState == null) { 
     // create the fragments for the first time 
     ft.add(R.id.view_flip, new SupportMapFragment(), TAG_FRAGMENT_MAP); 
     ft.commit(); 
    } 
} 

// ... 

public void onViewStateRestored(Bundle savedInstanceState) { 
    super.onViewStateRestored(savedInstanceState); 
    mMapFragment = (SupportMapFragment)findFragmentByTag(TAG_FRAGMENT_MAP); 
}