请求权限对话框会暂停我的活动 [英] Request permission dialog pauses my activity

查看:53
本文介绍了请求权限对话框会暂停我的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的活动的 onActivityResult 内请求许可,发生的事情是我的活动在显示请求许可权对话框时被暂停.为什么会这样,我可以以某种方式阻止它吗?

I am asking for permission inside onActivityResult of my activity and what is happening is that my activity is being paused while request permission dialog is displayed. Why is that and can I somehow prevent it?

我所做的只是以正常方式请求许可:

All I doing is asking for permission in a normal way:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
                ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
                requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION},
                        REQUEST_LOCATION_ACCESS_CODE);

推荐答案

正在发生的事情是我的活动在请求时被暂停了显示权限对话框.为什么会这样?

what is happening is that my activity is being paused while request permission dialog is displayed. Why is that?

此方法可能会启动一项活动,允许用户选择哪个活动授予和拒绝的权限.因此,您应该已准备好您的活动可以暂停和恢复.进一步,授予某些权限可能需要重新启动您的应用程序.在在这种情况下,系统将在重新创建活动堆栈之前将结果传递到您的onRequestPermissionsResult(int,String [],int []).

This method may start an activity allowing the user to choose which permissions to grant and which to reject. Hence, you should be prepared that your activity may be paused and resumed. Further, granting some permissions may require a restart of you application. In such a case, the system will recreate the activity stack before delivering the result to your onRequestPermissionsResult(int, String[], int[]).

尽管另一种解决方案是在可能的情况下将代码移动到 onStop

Although an another solution is move your code in onStop if possible and suitable

这篇关于请求权限对话框会暂停我的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆