Open wurstnudl opened 8 years ago
Hi,
the problem was somehow that the ImageFragments are being retained which should have been destroyed. Didn't really find out why this happens, what helps as workaround though is the following (it's the onDestroy of the fragment I'm using the scrollGallery in):
List
fragments = supportFragmentManager.getFragments(); FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction(); for (Fragment currentFragment : fragments) { if (currentFragment instanceof ImageFragment) { fragmentTransaction.remove(currentFragment); } } if (fragmentTransaction.commit() < 0) { // don't care. basically means that those fragments have no backstack entries }
@wurstnudl Much thanks for your research. :+1: I'll try to fix this for the next release.
@VEINHORN After some more research (onDestroy seems not to be the right place for this peace of code), I ran across the following SDK bug. It's marked as fixed, but I think it's not...and I'm not the only one.
@VEINHORN Actually the problem is a lot simpler than thought. I think the fragments of the view pager are destroyed when an activity is destroyed, you can leave that handling to android probably. You could add nullchecks to the ImageFragment on lines 41 and 42 for the viewPager and the backgroundImage. I was able to fix it that way for now, I set my own patched slide adapter via reflection which instantiates a patched ImageFragment with those nullchecks and everything works fine.
Thanks for now.
@wurstnudl can you post more information for how to fix this bug?
Any fix for this... I can recreate it everytime. Whenever i try to swipe back or select a previous image the following error is thrown.
Attempt to invoke virtual method 'void com.veinhorn.scrollgalleryview.HackyViewPager.setLocked(boolean)' on a null object reference
@nidhinprathap Hi. Which version of library do you use?
Hi,
this behaviour is not always reproducable. Happens during device rotation, currently on a Genymotion Nexus 7 with android 4.1.1.
Let me know if you need more info. Not sure why the viewpager is null here.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.veinhorn.scrollgalleryview.HackyViewPager.setLocked(boolean)' on a null object reference at com.veinhorn.scrollgalleryview.ImageFragment.onCreateView(ImageFragment.java:41) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1234) at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2046) at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:174) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:598) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237) at android.app.Activity.performStart(Activity.java:6268)