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

utilcodex:1.26.0 因为主题不一导致的崩溃 com.blankj.utilcode.util.Utils$TransActivity 不是Theme.AppCompat 主题 #1207

Closed
prczhb opened this issue Mar 30, 2020 · 12 comments

Comments

@prczhb
Copy link

prczhb commented Mar 30, 2020

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.

@Blankj
Copy link
Owner

Blankj commented Mar 30, 2020

辛苦你梳理了,你是个明白人哈,这个问题我这边已经解决了,可以试用 utilcode-1.26.1-release0 这个版本看看

@Blankj
Copy link
Owner

Blankj commented Mar 30, 2020

codex 的还没有,哈哈,那需要等下了

@prczhb
Copy link
Author

prczhb commented Mar 30, 2020

codex 的还没有,哈哈,那需要等下了

好吧 也谢谢大佬的开源精神 😁

@prczhb prczhb closed this as completed Mar 30, 2020
@prczhb
Copy link
Author

prczhb commented Apr 16, 2020

关于权限结束后的逻辑处理还存在问题/
比如判断权限后的回调中,如果展示一个弹窗,则这个弹窗仍然展示在了权限请求那个activity页面,仍然会跟着权限请求activity finish一起消失......

The version of utilcode: 'com.blankj:utilcodex:1.28.0'
The device: 小米6
The version of device: 29

@prczhb prczhb reopened this Apr 16, 2020
@Blankj
Copy link
Owner

Blankj commented Apr 16, 2020

对呀,现在就是提供给你们这个中转 Activity 给你们使用有问题吗?

@Blankj
Copy link
Owner

Blankj commented Apr 17, 2020

@prczhb 现在提供了这个 Activity 有什么问题吗

@prczhb
Copy link
Author

prczhb commented Apr 18, 2020

@prczhb 现在提供了这个 Activity 有什么问题吗

1.26之前的版本 在弹出权限框后(),回调已获取或拒绝接口,在回调里通过 ActivityUtils.getTopActivity(); 设置一个弹窗,没有问题.弹窗创建时权限的那个activity已经finish了;
但是
1.26以后的版本 包括现在的1.28 ,回调通过或拒绝权限,立即通过 ActivityUtils.getTopActivity(); 设置一个弹窗 ,这个弹窗就创建在了那个权限的activity里,接着会跟随activity一起finish了...

@prczhb
Copy link
Author

prczhb commented Apr 18, 2020

检测权限被拒绝后,我会立刻弹窗提示需要权限,而那个弹窗正好创建在了还未消失的权限activity上, 然后会跟着那个activity一起没了,这样我的逻辑就没啥用了

@Blankj
Copy link
Owner

Blankj commented Apr 18, 2020

好的,了解了

@Blankj
Copy link
Owner

Blankj commented Apr 18, 2020

@prczhb 试试 1.28.1 版本可以

@prczhb
Copy link
Author

prczhb commented Apr 18, 2020

@prczhb 试试 1.28.1 版本可以

image

image

如图中的执行顺序. 拒绝权限先走的回调,然后才activity,finish

@Blankj
Copy link
Owner

Blankj commented Apr 18, 2020

试试 1.28.1 版本哈,我测试是可以的,不过一般请求权限不都在 Activity 或者 Fragment 的么,你干嘛要非要获取 getTopActivity 呢?

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