如何在Fragment中调用OnActivityResult及其工作方式? [英] How can I call OnActivityResult inside Fragment and how it work?

查看:632
本文介绍了如何在Fragment中调用OnActivityResult及其工作方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在onActivityResult()上在Fragment中使用,如果可以,那么它如何工作,请举例说明.

I want to know is it possible on onActivityResult()to use inside Fragment and if yes then how it works please explain with example.

推荐答案

在您的片段中,您需要调用:

Within your fragment, you need to call:

startActivityForResult(myIntent, MY_INTENT_REQUEST_CODE);

其中myIntent是您已经定义的意图,MY_INTENT_REQUEST_CODE是您在此片段中定义为全局变量的int常量,作为此意图的请求代码.

where myIntent is the intent you already defined, and MY_INTENT_REQUEST_CODE is the int constant you defined in this fragment as a global variable as the request code for this intent.

然后,仍在片段中,您需要重写此方法:

And then, still inside your fragment, you need to override this method:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
   //super.onActivityResult(requestCode, resultCode, data); comment this unless you want to pass your result to the activity.
}

这篇关于如何在Fragment中调用OnActivityResult及其工作方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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