ParkSangGwon / TedBottomPicker

TedBottomPicker is simple image picker using bottom sheet
1.11k stars 185 forks source link

add check if getActivity() == null #151

Open bso112 opened 2 years ago

bso112 commented 2 years ago

TedBottomPicker uses ProxyActivity. and ProxyActivity stores ActivityRequest. So if configuration change occurs, ActivityRequest's OnActivityResultListener reference destroyed TedBottomSheetDialogFragment. This causes runtime Exception.

Failure delivering result ResultInfo{who=null, request=3457, result=-1, data=Intent { dat=content://media/external/images/media/7356 flg=0x1 (has extras) }} to activity {com.sample.android.demo/com.gun0912.tedonactivityresult.ProxyActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference

You can demonstrate this problem by enabling 'Don't keep activities' on the Developer Options In Android Phone Setting.

To solve this problem, we can either check getActivity() != null when invoking onActivityResult() or make ProxyActivity doesn't stores ActivityRequest. The former will skip processing the Activity result, but Runtime Exception will not occur. The Latter takes so many changes. So, I choose the former.