Seems like you account for the size -1 here, but then position is passed to mFragments.add below which can cause problems if that method doesn't know that it needs to use -1.