How to popBackStack fragments by tag like this:
If findByTag [b] is exist then clear all elements of stack which are above of current fragment.
else If findByTag [d] does not exist then
I can only guess what you question is. Here is a link to Google's Tasks and Back Stack guide for you that might help.