Destroy item from the ViewPager's adapter after screen orientation changed Destroy item from the ViewPager's adapter after screen orientation changed android android

Destroy item from the ViewPager's adapter after screen orientation changed


UPDATE: SOLUTION FOUND OK, so this took a while. The problem was that the destroyItem() callback was called twice on the progress fragment, once when the screen orientation changed and then once again after the api call finished. That's why the exception. The solution that I found is the following: Keep tracking if the api call finished or not and destroy the progress fragment just in this case, code below.

@Override        public void destroyItem(ViewGroup container, int position, Object object) {            if (object.equals(progressElement) && apiCallFinished == true) {                apiCallFinished = false;                currentFragments.put(position, currentFragments.get(position + 1));                super.destroyItem(container, position, object);            } else if (!(object.equals(progressElement))) {                currentFragments.put(position, null);                super.destroyItem(container, position, object);            }        }

and then this apiCallFinished is set to false in the constructor of the adapter and to true in the onTaskSuccess() callback. And it really works!