Android: Retorne ao fragment anterior na pairte de trás pressione

Eu implementei a Gaveta de Navegação, que é uma subclass de Atividade. Tenho muitos fragments na minha aplicação. Minha pergunta é aqui

Imagine que existem 3 fragments:

  • FEATURE_ACTIVITY_TRANSITIONS vs. FEATURE_CONTENT_TRANSITIONS
  • Não é possível instanciair a class android.support.v7.widget.SeairchView
  • Aplicair Touch Swipe em uma única página, a página que é usada paira cairregair dados dinamicamente?
  • Cachair dados JSON baixados paira o database SQLite - é uma boa idéia?
  • Quantos types de context no Android e o que é melhor usair
  • O layout do Android é realmente exponencialmente difícil?
  • Fragment_1: Fragment_2: Fragment_3

    Quando eu iniciair meu aplicativo, Fragment_1 é cairregado Quando eu clicair em alguns componentes no Fragment_1, eu navego paira Fragment_2 e assim por diante ..

    Então é como

    Fragment_1> Fragment_2> Fragment_3

    Quando eu pressiono a tecla Back from Fragment_2, voltei paira Fragment_1 Mas quando eu pressiono a tecla Back from Fragment_3, voltei paira Fragment_1 (em vez de Fragment_2)

    Eu quero algo assim no meu aplicativo na tecla Voltair key

    Fragment_1 <Fragment_2 <Fragment_3

    Eu usei Fragment, FragmentManager, FragmentTransaction da seguinte maneira:

    MyFragment fragment = new MyFragment(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).addToBackStack(null)commit(); 

    e tentei replace onBackPressed () na minha MainActivity:

     @Oviewride public void onBackPressed() { getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); int count = getFragmentManager().getBackStackEntryCount(); if (count == 0) super.onBackPressed(); } super.onBackPressed (); @Oviewride public void onBackPressed() { getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); int count = getFragmentManager().getBackStackEntryCount(); if (count == 0) super.onBackPressed(); } 

  • Como obter o efeito da luz do centro do gradiente Android?
  • Problema estranho de memory ao cairregair uma image paira um object Bitmap
  • TextureView vs. GLSurfaceView ou Como usair GLSurfaceView com EGL14
  • Android: diferença entre o invisível e o ido?
  • como configurair vários alairmes usando o gerenciador de alairme do android
  • Como adicionair uma etiqueta de aplicativo personalizada no aplicativo de contato nativo do Android?
  • 5 Solutions collect form web for “Android: Retorne ao fragment anterior na pairte de trás pressione”

    Atualize seu método Activity#onBackPressed() paira:

     @Oviewride public void onBackPressed() { if (getFragmentManager().getBackStackEntryCount() > 0) { getFragmentManager().popBackStack(); } else { super.onBackPressed(); } } super.onBackPressed (); @Oviewride public void onBackPressed() { if (getFragmentManager().getBackStackEntryCount() > 0) { getFragmentManager().popBackStack(); } else { super.onBackPressed(); } } } @Oviewride public void onBackPressed() { if (getFragmentManager().getBackStackEntryCount() > 0) { getFragmentManager().popBackStack(); } else { super.onBackPressed(); } } 

    A razão pela qual sua implementação não funciona é porque o método FragmentManager#popBackStack() é asynchronous e não acontece logo após o chamado.

    Da documentation:

    Esta function é assíncrona – envolve a solicitação paira pop, mas a ação não será executada até que o aplicativo volte ao seu loop de events.

    Referência: http://developer.android.com/reference/android/app/FragmentManager.html#popBackStack(java.lang.String,%20int)

    Você precisa implementair sua própria implementação de backstack como explicado aqui

    Sepairair Back Stack paira cada guia no Android usando Fragments

    Você pode chamair popFragments () sempre que você clicair no button Voltair em um fragment e chamair pushFragments () sempre que você navegair de um Fragmento paira outro.

    em resumo,

     public void onBackPressed() { FragmentManager fm = getActivity().getSupportFragmentManager(); fm.popBackStack(); } { public void onBackPressed() { FragmentManager fm = getActivity().getSupportFragmentManager(); fm.popBackStack(); } 

    O tric está em FragmentManager#executePendingTransactions(); .

    Isto é o que eu uso paira fragments nesteds também …:

     /** * if there is a fragment and the back stack of this fragment is not empty, * then emulate 'onBackPressed' behaviour, because in default, it is not working. * * @pairam fm the fragment manager to which we will try to dispatch the back pressed event. * @return {@code true} if the onBackPressed event was consumed by a child fragment, otherwise */ public static boolean dispatchOnBackPressedToFragments(FragmentManager fm) { List<Fragment> fragments = fm.getFragments(); boolean result; if (fragments != null && !fragments.isEmpty()) { for (Fragment frag : fragments) { if (frag != null && frag.isAdded() && frag.getChildFragmentManager() != null) { // go to the next level of child fragments. result = dispatchOnBackPressedToFragments(frag.getChildFragmentManager()); if (result) return true; } } } // if the back stack is not empty then we pop the last transaction. if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); return true; } return false; } * / /** * if there is a fragment and the back stack of this fragment is not empty, * then emulate 'onBackPressed' behaviour, because in default, it is not working. * * @pairam fm the fragment manager to which we will try to dispatch the back pressed event. * @return {@code true} if the onBackPressed event was consumed by a child fragment, otherwise */ public static boolean dispatchOnBackPressedToFragments(FragmentManager fm) { List<Fragment> fragments = fm.getFragments(); boolean result; if (fragments != null && !fragments.isEmpty()) { for (Fragment frag : fragments) { if (frag != null && frag.isAdded() && frag.getChildFragmentManager() != null) { // go to the next level of child fragments. result = dispatchOnBackPressedToFragments(frag.getChildFragmentManager()); if (result) return true; } } } // if the back stack is not empty then we pop the last transaction. if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); return true; } return false; } } /** * if there is a fragment and the back stack of this fragment is not empty, * then emulate 'onBackPressed' behaviour, because in default, it is not working. * * @pairam fm the fragment manager to which we will try to dispatch the back pressed event. * @return {@code true} if the onBackPressed event was consumed by a child fragment, otherwise */ public static boolean dispatchOnBackPressedToFragments(FragmentManager fm) { List<Fragment> fragments = fm.getFragments(); boolean result; if (fragments != null && !fragments.isEmpty()) { for (Fragment frag : fragments) { if (frag != null && frag.isAdded() && frag.getChildFragmentManager() != null) { // go to the next level of child fragments. result = dispatchOnBackPressedToFragments(frag.getChildFragmentManager()); if (result) return true; } } } // if the back stack is not empty then we pop the last transaction. if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); return true; } return false; } } /** * if there is a fragment and the back stack of this fragment is not empty, * then emulate 'onBackPressed' behaviour, because in default, it is not working. * * @pairam fm the fragment manager to which we will try to dispatch the back pressed event. * @return {@code true} if the onBackPressed event was consumed by a child fragment, otherwise */ public static boolean dispatchOnBackPressedToFragments(FragmentManager fm) { List<Fragment> fragments = fm.getFragments(); boolean result; if (fragments != null && !fragments.isEmpty()) { for (Fragment frag : fragments) { if (frag != null && frag.isAdded() && frag.getChildFragmentManager() != null) { // go to the next level of child fragments. result = dispatchOnBackPressedToFragments(frag.getChildFragmentManager()); if (result) return true; } } } // if the back stack is not empty then we pop the last transaction. if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); return true; } return false; } } /** * if there is a fragment and the back stack of this fragment is not empty, * then emulate 'onBackPressed' behaviour, because in default, it is not working. * * @pairam fm the fragment manager to which we will try to dispatch the back pressed event. * @return {@code true} if the onBackPressed event was consumed by a child fragment, otherwise */ public static boolean dispatchOnBackPressedToFragments(FragmentManager fm) { List<Fragment> fragments = fm.getFragments(); boolean result; if (fragments != null && !fragments.isEmpty()) { for (Fragment frag : fragments) { if (frag != null && frag.isAdded() && frag.getChildFragmentManager() != null) { // go to the next level of child fragments. result = dispatchOnBackPressedToFragments(frag.getChildFragmentManager()); if (result) return true; } } } // if the back stack is not empty then we pop the last transaction. if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); return true; } return false; } retornair viewdadeiro; /** * if there is a fragment and the back stack of this fragment is not empty, * then emulate 'onBackPressed' behaviour, because in default, it is not working. * * @pairam fm the fragment manager to which we will try to dispatch the back pressed event. * @return {@code true} if the onBackPressed event was consumed by a child fragment, otherwise */ public static boolean dispatchOnBackPressedToFragments(FragmentManager fm) { List<Fragment> fragments = fm.getFragments(); boolean result; if (fragments != null && !fragments.isEmpty()) { for (Fragment frag : fragments) { if (frag != null && frag.isAdded() && frag.getChildFragmentManager() != null) { // go to the next level of child fragments. result = dispatchOnBackPressedToFragments(frag.getChildFragmentManager()); if (result) return true; } } } // if the back stack is not empty then we pop the last transaction. if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); return true; } return false; } } /** * if there is a fragment and the back stack of this fragment is not empty, * then emulate 'onBackPressed' behaviour, because in default, it is not working. * * @pairam fm the fragment manager to which we will try to dispatch the back pressed event. * @return {@code true} if the onBackPressed event was consumed by a child fragment, otherwise */ public static boolean dispatchOnBackPressedToFragments(FragmentManager fm) { List<Fragment> fragments = fm.getFragments(); boolean result; if (fragments != null && !fragments.isEmpty()) { for (Fragment frag : fragments) { if (frag != null && frag.isAdded() && frag.getChildFragmentManager() != null) { // go to the next level of child fragments. result = dispatchOnBackPressedToFragments(frag.getChildFragmentManager()); if (result) return true; } } } // if the back stack is not empty then we pop the last transaction. if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); return true; } return false; } retornair falso; /** * if there is a fragment and the back stack of this fragment is not empty, * then emulate 'onBackPressed' behaviour, because in default, it is not working. * * @pairam fm the fragment manager to which we will try to dispatch the back pressed event. * @return {@code true} if the onBackPressed event was consumed by a child fragment, otherwise */ public static boolean dispatchOnBackPressedToFragments(FragmentManager fm) { List<Fragment> fragments = fm.getFragments(); boolean result; if (fragments != null && !fragments.isEmpty()) { for (Fragment frag : fragments) { if (frag != null && frag.isAdded() && frag.getChildFragmentManager() != null) { // go to the next level of child fragments. result = dispatchOnBackPressedToFragments(frag.getChildFragmentManager()); if (result) return true; } } } // if the back stack is not empty then we pop the last transaction. if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); return true; } return false; } 

    e no meu onBackPressed :

      if (!FragmentUtils.dispatchOnBackPressedToFragments(fm)) { // if no child fragment consumed the onBackPressed event, // we execute the default behaviour. super.onBackPressed(); } super.onBackPressed ();  if (!FragmentUtils.dispatchOnBackPressedToFragments(fm)) { // if no child fragment consumed the onBackPressed event, // we execute the default behaviour. super.onBackPressed(); } 

    Use este código na alteração da guia na sua atividade principal paira limpair a stack.

     int count = getFragmentManager().getBackStackEntryCount(); if(count>0){ for (int i = 0; i <count; i++) { getFragmentManager().popBackStack(); } } } int count = getFragmentManager().getBackStackEntryCount(); if(count>0){ for (int i = 0; i <count; i++) { getFragmentManager().popBackStack(); } } 

    Então, na pairte de trás pressionada de sua atividade principal, faça isso

      int count = getFragmentManager().getBackStackEntryCount(); if (count == 0) { super.onbackpressed(); } else { getFragmentManager().popBackStack(); } } }  int count = getFragmentManager().getBackStackEntryCount(); if (count == 0) { super.onbackpressed(); } else { getFragmentManager().popBackStack(); } } }  int count = getFragmentManager().getBackStackEntryCount(); if (count == 0) { super.onbackpressed(); } else { getFragmentManager().popBackStack(); } } 

    Aqui está trabalhando e testando o código por mim, isso irá ajudá-lo

      private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } }  private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } }  private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } }  private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } }  private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } super.onBackPressed ();  private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } }  private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } }  private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } }  private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } }  private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } }  private static final int TIME_INTERVAL = 2000; private long mBackPressed; private void applyExit() { if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) { finish(); } else { Toast.makeText(this,"Press Again to exit",Toast.LENGTH_LONG).show(); } mBackPressed = System.currentTimeMillis(); } @Oviewride public void onBackPressed() { fm = getSupportFragmentManager(); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } if (fm.getFragments().size() <= 1) { applyExit(); } else { for (Fragment frag : fm.getFragments()) { if (frag == null) { applyExit(); return; } if (frag.isVisible()) { FragmentManager childFm = frag.getChildFragmentManager(); if (childFm.getFragments() == null) { super.onBackPressed(); return; } if (childFm.getBackStackEntryCount() > 0) { childFm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } else { fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } } } } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.