How to restrict fragment from adding to top of stack if it already exist in the top of stack in android

29 views Asked by At

Is there any way that i can achieve the launch mode single top feature in activity with fragment. Actually what i need is if there is any fragment exist on the top of the stack and if i am trying to add again, it should point to the same one which is already available on the top of the stack. Please help.

1

There are 1 answers

0
nick9999 On

You can get fragment which is on top of the stack by this way getFragmentManager().getBackStackEntryAt(getFragmentManager().getBackStackEntryCount()-1)

Check if this is same as your fragment or not.