0

Android 백 스택 한 조각, 하드웨어를 누르면 백 버튼이 백 스택을 나타냅니다. 내가 탐색 서랍 하나 개의 활동이Android 백 스택 한 조각, 하드웨어를 누르면 백 버튼이 백 스택을 나타냅니다.

:

다음은 내 예상 시나리오입니다. 각 탐색 요소는 클릭시 다른 조각으로 이동합니다. 홈 조각 만 다시 스택 싶습니다. 다른 조각에서 뒤로 버튼을 누르면 홈 조각으로 이동합니다. 홈 프래그먼트에서 뒤로 버튼을 누르면 앱이 종료됩니다.

답변

2

당신은 라인을 주석 이 방법에 방법을 onBackPressed 처리 할 수 ​​//super.onBackPressed();

@Override 
     public void onBackPressed() { 
//   super.onBackPressed(); 
//Now check if current fragment is not home fragment 
// then replace current fragment with home fragment 
//if current fragment is home fragment then execute the following code 
Intent homeIntent = new Intent(Intent.ACTION_MAIN); 
    homeIntent.addCategory(Intent.CATEGORY_HOME); 
    homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    startActivity(homeIntent); 

     } 
관련 문제