onBackPressed
함수를 재정의하여 현재 작업중인 앱의 뒤쪽 키의 동작을 변경합니다..remove (프래그먼트)를 호출 한 후 프래그먼트가 삭제되지 않습니다.
FragmentTransaction에 특정 태그 qFrag
이 포함 된 조각이 포함 된 경우보기에서 조각을 애니메이션화해야합니다.
그러나 조각을 제거한 후에도 조각은 여전히 나타납니다. 이 때문에 내 if 문의 조건 인 else
에 결코 도달하지 못합니다.
@Override
public void onBackPressed() {
// After pressing the back key a second time, questionFrag still has a value.
Fragment questionFrag = getSupportFragmentManager().findFragmentByTag("qFrag");
// If question fragment in the fragment manager
if (questionFrag != null) {
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_up, R.anim.slide_down)
.replace(R.id.main_menu_content_frame_layout, new Fragment(), "temp")
.remove(questionFrag)
.commit();
} else {
finish();
}
}
누군가가 트랜잭션 관리자에서 조각을 적절하게 제거하는 방법에 대해 조언 해 줄 수 있습니까?
if (questionFrag != null) {
getSupportFragmentManager()
.beginTransaction()
.remove(questionFrag)
.add(R.id.main_menu_content_frame_layout, new Fragment(), "temp")
.setCustomAnimations(R.anim.slide_up, R.anim.slide_down)
.commit();
System.out.println("questionFrag removed successfully");
finish()
} else {
finish();
}
당신은 System.out에를 추가 할 수 있습니다
감사합니다. 주제에 어려움을 겪어 왔지만 이것이 분명 도움이됩니다. – Airagale