将数据从活动返回到片段 [英] Returning data from activity to fragment

查看:75
本文介绍了将数据从活动返回到片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在打开片段视图触摸上的活动.如何将数据返回到打开活动"的片段.

I'm opening an Activity on fragment view touch. how to get data back to the fragment which opens the Activity.

推荐答案

1-首先,您必须使用 startActivityForResult()

1- First you'll have to start the Activity from your fragment using startActivityForResult()

2-确保在活动的 onActivityResult()方法中调用 super.onActivityResult (如果正在实现)

2- Make sure to call super.onActivityResult in your Activity's onActivityResult() method ( if you're implementing it)

3-在片段中,您只需实现 onActivityResult()并根据需要处理结果

3-Inside your fragment, you just need to implement onActivityResult() and handle the result as you wish

这篇关于将数据从活动返回到片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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