Explorar o código

Fix #299 如果不设置lifecycleRegistry,会出现空指针

zhpanvip %!s(int64=2) %!d(string=hai) anos
pai
achega
f46b5c7b9c

+ 4 - 4
bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java

@@ -516,10 +516,10 @@ public class BannerViewPager<T> extends RelativeLayout implements LifecycleObser
     if (!isLooping
         && isAutoPlay()
         && mBannerPagerAdapter != null
-        &&
-        mBannerPagerAdapter.getListSize() > 1
-        && isAttachedToWindow()
-        && lifecycleRegistry.getCurrentState() == Lifecycle.State.RESUMED) {
+        && mBannerPagerAdapter.getListSize() > 1
+        && isAttachedToWindow() && (lifecycleRegistry == null
+        || lifecycleRegistry.getCurrentState() == Lifecycle.State.RESUMED
+        || lifecycleRegistry.getCurrentState() == Lifecycle.State.CREATED)) {
       mHandler.postDelayed(mRunnable, getInterval());
       isLooping = true;
     }