Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalStateException PictureSelectorPreviewFragment not attached to an activity #2627

Closed
po1xiao opened this issue Mar 18, 2023 · 1 comment

Comments

@po1xiao
Copy link
Contributor

po1xiao commented Mar 18, 2023

Current use version?

当前使用的版本是多少?

3.10.8

Will this problem occur in demo?

Demo能否复现这问题?

否,特定情况小的小概率问题。

Describe the problem or provide an error log?

描述问题或提供错误log?

Fragment PictureSelectorPreviewFragment{4d038ea} (7edb7409-3f6b-42ea-8675-a4a3c65553f7) not attached to an activity.
androidx.fragment.app.Fragment.requireActivity(Fragment.java:995)
com.luck.picture.lib.PictureSelectorPreviewFragment$20.onAnimationEnd(PictureSelectorPreviewFragment.java:1327)
android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:608)
android.animation.AnimatorSet.endAnimation(AnimatorSet.java:1301)
android.animation.AnimatorSet.doAnimationFrame(AnimatorSet.java:1086)
android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:307)
android.animation.AnimationHandler.-$$Nest$mdoAnimationFrame(Unknown Source:0)
android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:86)
android.view.Choreographer$CallbackRecord.run(Choreographer.java:1386)
android.view.Choreographer$CallbackRecord.run(Choreographer.java:1396)
android.view.Choreographer.doCallbacks(Choreographer.java:1033)
android.view.ChoreographerExtImpl.checkScrollOptSceneEnable(ChoreographerExtImpl.java:399)
android.view.Choreographer.doFrame(Choreographer.java:900)
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1371)
android.os.Handler.handleCallback(Handler.java:942)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loopOnce(Looper.java:240)
android.os.Looper.loop(Looper.java:351)
android.app.ActivityThread.main(ActivityThread.java:8364)
java.lang.reflect.Method.invoke(Native Method)

修改建议:这段代码中,在Window window = requireActivity().getWindow();
前加个判断 if(getActivity() == null) return;

public void onAnimationEnd(Animator animation) {
    isAnimationStart = false;
    if (SdkVersionUtils.isP()) {
        Window window = requireActivity().getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        if (isAnimInit) {
            lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
            lp.layoutInDisplayCutoutMode =
                    WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
            window.setAttributes(lp);
            window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        } else {
            lp.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
            window.setAttributes(lp);
            window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }
    }
}
@LuckSiege
Copy link
Owner

下版本已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants