huburt-Hu / NewbieGuide

Android 快速实现新手引导层的库,通过简洁链式调用,一行代码实现引导层的显示
Apache License 2.0
3.56k stars 521 forks source link

check()方法报错,activity is null, please make sure that fragment is showing when call NewbieGuide #139

Closed callmexiaolu closed 5 years ago

callmexiaolu commented 5 years ago

在使用库之前进行了activity的判空操作,然后运行中还会发生异常抛出。 ` activity?.let { it.window.decorView.postDelayed({ if (showSwitchChild) { NewbieGuide.with(this) .setLabel("Dynamic") .alwaysShow(true) .addGuidePage(GuidePage.newInstance() .addHighLight(la_animation) .setLayoutRes(R.layout.dynamic_flag_guide)) .addGuidePage(GuidePage.newInstance() .addHighLight(RectF(0f, 0f, 0f, 0f)) .setLayoutRes(R.layout.dynamic_guide_hint)) .setOnGuideChangedListener(object : OnGuideChangedListener { override fun onRemoved(p0: Controller?) {

                                    }

                                    override fun onShowed(p0: Controller?) {
                                    }
                                })
                                .show()
                    } else {
                        NewbieGuide.with(this)
                                .setLabel("Dynamic")
                                .alwaysShow(true)
                                .addGuidePage(GuidePage.newInstance()
                                        .addHighLight(la_animation)
                                        .setLayoutRes(R.layout.dynamic_flag_guide))
                                .setOnGuideChangedListener(object : OnGuideChangedListener {
                                    override fun onRemoved(p0: Controller?) {

                                    }

                                    override fun onShowed(p0: Controller?) {
                                    }
                                })
                                .show()
                    }
                }, 1000)
            }`
callmexiaolu commented 5 years ago

找到原因了:是因为fragment实例化后,所依附的activity后续被回收了,但是该fragment实例依旧存在,导致使用库的时候通过该fragment获取的activity为null