当用户在android应用程序的手机设置中撤销权限时,该进程将被终止/终止,当用户再次打开该应用程序时,它将崩溃。有没有可能应用程序不会崩溃,以便用户留在他或她刚刚离开的活动中?如果有,是如何实现的?我仍然是android开发的新手。
发布于 2018-11-08 17:36:31
当应用程序重新打开时,你可以捕获onResume,并检查在关闭权限之前,你是否仍然有权限继续他们正在做的事情。
@Override
protected void onResume()
{
super.onResume();
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
{
//We have the location permission!
//We can continue :)
}
else
{
//We don't have the permission anymore :(
finish();
//Or we can request it again, maybe show a dialog saying that it's needed in order to continue?
}
}发布于 2018-11-08 21:58:22
请注意,在onResume()方法中请求权限不是一个好主意,因为如果用户没有授予权限,则会出现一个对话框,询问用户是否授予权限,活动将进入onPause()状态。然后,如果用户拒绝权限,活动将返回到onResume()状态并再次请求权限,如果用户不批准或选中“不要再问我”checkBox,这将导致无限循环。我建议您在onStart()方法中实现逻辑。
https://stackoverflow.com/questions/53204711
复制相似问题