0

It seems to me that a very basic functionality, which is to clear back stack, is absent from the FragmentManager API, i am posting this question because i want to know if its just poor design or is there good reasons that i dont yet realize for the following :

  1. I happen to find my self in a situation where i need to clean back stack and start it fresh, there is no proper way of doing it, the only way i am aware of after google searching is this (or alike) :

    while (supportFragmentManager.popBackStackImmediate()); supportFragmentManager.beginTransaction().replace(R.id.content, freshStartFragment).commit();

The problem about this is that transactions with animations are being executed on main thread stucking GUI for no reason what so ever

  1. getBackStackEntryAt seemed to be promissing when i was facing problem 1, I thought it is reasonable that actual transaction would be available through a BackStackEntry but unluckily this class seem very redundent

  2. Continuing comment 2, as back stack contains transactions, i would expect a getter for them so i can edit them, for example to make them show no animtaion so that the code in 1 would work well.

To put it in short, Why would i have to go all that way just to clean back stack? What good reason is there for the FragmentManager designer to exclude a simple cleanBackStack method?

Enlighten me :)

NOTE: My question is diffrent then Clear back stack using fragments as i am not asking how (as there are many posts that have answers for that), i am asking why would a simple basic functionality need to be implemented in such a hacky way? the biggest problem (which itself has hacky solutions too) about this hacky solution is that the GUI thread gets stuck while executing the pops...

Community
  • 1
  • 1
Ofek Ron
  • 8,354
  • 13
  • 55
  • 103
  • possible duplicate of [Clear back stack using fragments](http://stackoverflow.com/questions/6186433/clear-back-stack-using-fragments) – Mike M. May 31 '15 at 07:34
  • @MikeM. this is not the same questions, I am not asking How, as i seen this post and others and mentioned the way i do it in the post. what i wish to discuss about is Why would it be so complex to do such a basic task? wanted to know if i am missing something, because all the solutions currently exists for this problem are not more then HACKS, and not so elegant and efficient ones. – Ofek Ron May 31 '15 at 07:42
  • My apologies. I had trouble understanding your post. In that case, your question is then "primarily opinion-based". Any speculation as to the design decisions of the Google developers would be guesswork, and inherently opinionated. The API is what it is (until it changes again). – Mike M. May 31 '15 at 07:54
  • @MikeM. Maybe someone can give us a good explanation for why this option is missing, i dont believe that they just forgot to think about the need to clear the stack... – Ofek Ron May 31 '15 at 08:01

0 Answers0