LuckSiege / LuckSiege/PictureSelector

IllegalStateException fragment销毁重建

Open
#2,835 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
13.6k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

## Current use version?
#### 当前使用的版本是多少?

```
v3.11.2
```

## Will this problem occur in demo?
#### Demo能否复现这问题?

```
能 [类似](https://zhuanlan.zhihu.com/p/643081313)
```

## Describe the problem or provide an error log?
#### 描述问题或提供错误log?

```
这个bug可能是和fragment的状态销毁和重建有关的,addToBackStack;
java.lang.RuntimeException:Failure delivering result ResultInfo{who=null, request=190060639, result=0, data=null} to activity {com.xxx.xxx/com.xxx.component_xx.XXXClockInActivity}: java.lang.IllegalStateException: Fragment PictureOnlyCameraFragment{4f0a3e7} (0fd89e6d-32f0-4c42-b3ce-55e854c4000b id=0x1020002 tag=PictureOnlyCameraFragment) did not return a View from onCreateView() or this was called before onCreateView().
2 android.app.ActivityThread.deliverResults(ActivityThread.java:5787)
3 ......
4 Caused by:
5 java.lang.IllegalStateException:Fragment PictureOnlyCameraFragment{4f0a3e7} (0fd89e6d-32f0-4c42-b3ce-55e854c4000b id=0x1020002 tag=PictureOnlyCameraFragment) did not return a View from onCreateView() or this was called before onCreateView().
6 androidx.fragment.app.Fragment.requireView(Fragment.java:32)
7 com.wahaha.component_ui.utils.a0$d.onDismiss(PictureKtUtils.kt:6)
8 com.luck.picture.lib.basic.PictureCommonFragment.onPermissionExplainEvent(PictureCommonFragment.java:21)
9 com.luck.picture.lib.PictureOnlyCameraFragment.handlePermissionSettingResult(PictureOnlyCameraFragment.java:3)
10 com.luck.picture.lib.basic.PictureCommonFragment.onActivityResult(PictureCommonFragment.java:381)
11 com.luck.picture.lib.PictureOnlyCameraFragment.onActivityResult(PictureOnlyCameraFragment.java:1)
12 androidx.fragment.app.FragmentManager$8.onActivityResult(FragmentManager.java:10)
13 androidx.fragment.app.FragmentManager$8.onActivityResult(FragmentManager.java:1)
14 androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:23)
15 androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:2)
16 androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:3)
17 androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:6)
18 com.wahaha.component_map.VisitClockInActivity.onActivityResult(VisitClockInActivity.java:1)
19 android.app.Activity.dispatchActivityResult(Activity.java:8541)
20 android.app.ActivityThread.deliverResults(ActivityThread.java:5780)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with PictureOnlyCameraFragment.handlePermissionSettingResult and PictureCommonFragment.onActivityResult, then trace the call into PictureKtUtils.kt and Fragment.requireView shown in the stack trace. Reproduce the permission-result flow while the fragment is destroyed and recreated; done means the flow no longer calls requireView before onCreateView and does not raise the reported IllegalStateException.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, kotlin
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.