Closed
Description
Describe the bug
申请权限后迅速在回调中显示自己的弹窗 结果崩溃.
A clear and concise description of what the bug is.
- The version of utilcode: 'com.blankj:utilcodex:1.26.0'
- The device: 小米6
- The version of device: 29
The code of bug
插件内的申请权限后在回调中迅速进行了我自己的dialog展示
我的dialog是AlertDialog ,需要主题Theme.AppCompat ,而我应用中application节点中已设置了这个主题,
不过我dialog中是通过()
Activity topActivity = ActivityUtils.getTopActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(topActivity);
目前看来是获取到了 TransActivity (弹权限框的那个activity) ,
但是该插件弹出的 TransActivity 看来不是该主题的. 所以导致了崩溃
我在申请权限后的回调中加入了handler延时, 结果正常了.因为在这延时中 TransActivity 已经finish了.
然后 Activity topActivity = ActivityUtils.getTopActivity(); 获取到的就是我自己的activity了, 这样就没有崩溃了.
或者我吧我的AlertDialog 改成了 普通的Dialog , 但是因为显示在 TransActivity ,他finish了 ,我的弹窗也跟着他没有了
但是这两个方法怎么看起来都优点别扭,该怎么解决呢.
## 不过 在1.25.9中 没有以上的问题
The stack of crash
2020-03-30 17:48:39.095 12822-12822/com.xxx.xxxxxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.xxxxxx, PID: 12822
java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=1, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.xxx.xxxxxx/com.blankj.utilcode.util.Utils$TransActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.deliverResults(ActivityThread.java:4472)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4514)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1840)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:6878)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:659)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:552)
at androidx.appcompat.app.AppCompatDialog.setContentView(AppCompatDialog.java:95)
at androidx.appcompat.app.AlertController.installContent(AlertController.java:232)
at androidx.appcompat.app.AlertDialog.onCreate(AlertDialog.java:279)
at android.app.Dialog.dispatchOnCreate(Dialog.java:407)
at android.app.Dialog.show(Dialog.java:302)
at com.xxxx.xxxxxx.base.util.DialogHelper.showLoadingDialog(DialogHelper.java:397)
at com.xxxx.xxxxxx.patient.ui.splash.SplashActivity.initConfig(SplashActivity.java:130)
at com.xxxx.xxxxxx.patient.ui.splash.SplashActivity.lambda$null$1$SplashActivity(SplashActivity.java:113)
at com.xxxx.xxxxxx.patient.ui.splash.-$$Lambda$SplashActivity$0slgHttgekLk9huYV9O_B0UE3_E.onPermissionDenied(Unknown Source:2)
at com.xxxx.xxxxxx.base.util.PermissionHelper$1.onDenied(PermissionHelper.java:109)
at com.blankj.utilcode.util.PermissionUtils.requestCallback(PermissionUtils.java:343)
at com.blankj.utilcode.util.PermissionUtils.onRequestPermissionsResult(PermissionUtils.java:353)
at com.blankj.utilcode.util.PermissionUtils.access$1000(PermissionUtils.java:39)
at com.blankj.utilcode.util.PermissionUtils$PermissionActivityImpl.onRequestPermissionsResult(PermissionUtils.java:417)
at com.blankj.utilcode.util.Utils$TransActivity.onRequestPermissionsResult(Utils.java:403)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7757)
at android.app.Activity.dispatchActivityResult(Activity.java:7602)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4465)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4514)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1840)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:6878)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
Screenshots
If applicable, add screenshots to help explain your problem.
Please delete the current line and the followings.
Thank you for supporting AndroidUtilCode.
Metadata
Metadata
Assignees
Labels
No labels