3

I have a Fragment stack, which fragments are added to (not replaced). The problem is, because of memory issues, I don't want to have more than a specific amount of fragments in the stack. Suppose I have added fragments A, B, C, D to the stack. Now that I want to add the Fragment E, I want the A to be removed, using this piece of code:

fragmentManager.beginTransaction().remove(fragmentA).commit()

I get fragmentA using findFragmentByTag() and I am sure fragmentA exists and is in the stack. But this has no effect, and doesn't remove fragmentA.

What's wrong you think?
Is it possible to remove a fragment from bottom of the stack?

Kayhan Asghari
  • 2,817
  • 1
  • 28
  • 47
  • *What's wrong you think?* You assumption that it *has no effect, and doesn't remove* is wrong ... How did you check it? – Selvin Feb 24 '16 at 16:25
  • I press back until I reach fragment A, and it exists. getBackStackCount also proves and also calling findFragmentByTag again with the same tag finds the fragment that should have been removed. – Kayhan Asghari Feb 24 '16 at 16:36
  • try calling executePendingTransactions http://developer.android.com/intl/es/reference/android/app/FragmentManager.html#executePendingTransactions() – diedu Feb 24 '16 at 17:18
  • @diedu tried, but didn't work. – Kayhan Asghari Feb 25 '16 at 08:27
  • see this to get how you can write your stack : http://stackoverflow.com/questions/12854105/custom-back-stack-for-each-fragment-in-tabhost-in-android – Shayan Pourvatan Mar 06 '16 at 08:12

0 Answers0