android onresume方法,Android onActivityResult()和onResume()的执行顺序

android onresume方法,Android onActivityResult()和onResume()的执行顺序问题回顾:在Android8.0手机上不能直接安装Apk,需要权限申请,回调后执行onActivityResult()方法,并弹出对应的dialog,这时需要判断当前Activity是否处于resume状态,通过变量来控制,但结果是这个dialog并不会弹出。问题本质Activity跳转到系统应用后回调onActivityResult()先执行还是onResume()先执行?查看源码/***C…

大家好,又见面了,我是你们的朋友全栈君。

问题回顾:

在Android8.0手机上不能直接安装Apk,需要权限申请,回调后执行onActivityResult()方法,并弹出对应的dialog,这时需要判断当前Activity是否处于resume状态,通过变量来控制,但结果是这个dialog并不会弹出。

问题本质

Activity跳转到系统应用后回调onActivityResult() 先执行还是onResume()先执行?

查看源码

/**

* Called when an activity you launched exits, giving you the requestCode

* you started it with, the resultCode it returned, and any additional

* data from it. The resultCode will be

* {@link #RESULT_CANCELED} if the activity explicitly returned that,

* didn’t return any result, or crashed during its operation.

*

*

You will receive this call immediately before onResume() when your

* activity is re-starting.

*

*

This method is never invoked if your activity sets

* {@link android.R.styleable#AndroidManifestActivity_noHistory noHistory} to

* true.

*

* @param requestCode The integer request code originally supplied to

* startActivityForResult(), allowing you to identify who this

* result came from.

* @param resultCode The integer result code returned by the child activity

* through its setResult().

* @param data An Intent, which can return result data to the caller

* (various data can be attached to Intent “extras”).

*

* @see #startActivityForResult

* @see #createPendingResult

* @see #setResult(int)

*/

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

}

onActivityResult()注释中有这么一句话:

You will receive this call immediately before onResume() when your activity is re-starting.

(意思是说当你的Activity重新启动时 onActivityResult() 会在onResume()之前执行)

很显然,如果你的Activity 调用了 startActivityForResult() 方法启动,回调之后会先执行 onActivityResult() ,然后执行onResume()

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/139798.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号