有没有一种方法可以像开始片段的结果一样工作? [英] Is there a method that works like start fragment for result?

查看:20
本文介绍了有没有一种方法可以像开始片段的结果一样工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在叠加层中有一个片段.这是用于登录服务.在电话应用程序中,我想在叠加层中显示的每个步骤都是它们自己的屏幕和活动.登录过程分为 3 个部分,每个部分都有自己的活动,通过 startActivityForResult() 调用.

I currently have a fragment in an overlay. This is for signing in to the service. In the phone app, each of the steps I want to show in the overlay are their own screens and activities. There are 3 parts of the sign-in process and each had their own activity that was called with startActivityForResult().

现在我想使用片段和覆盖来做同样的事情.叠加层将显示与每个活动相对应的片段.问题是这些片段托管在 Honeycomb API 的一个活动中.我可以让第一个片段工作,但是我需要 startActivityForResult(),这是不可能的.是否有一些类似于 startFragmentForResult() 的内容,我可以在其中启动一个新片段,并在完成后将结果返回给前一个片段?

Now I want to do the same thing using fragments and an overlay. The overlay will show a fragment corresponding to each activity. The problem is that these fragments are hosted in an activity in the Honeycomb API. I can get the first fragment working, but then I need to startActivityForResult(), which isn't possible. Is there something along the lines of startFragmentForResult() where I can kick off a new fragment and when it's done have it return a result to the previous fragment?

推荐答案

所有的 Fragment 都存在于活动中.为结果启动一个 Fragment 没有多大意义,因为容纳它的 Activity 总是可以访问它,反之亦然.如果 Fragment 需要传递一个结果,它可以访问它的 Activity 并设置它的结果并完成它.在单个 Activity 中交换 Fragment 的情况下,该 Activity 仍然可以被两个 Fragment 访问,并且您的所有消息传递都可以简单地通过 Activity.

All of the Fragments live inside Activities. Starting a Fragment for a result doesn't make much sense, because the Activity that houses it always has access to it, and vice versa. If the Fragment needs to pass on a result, it can access its Activity and set its result and finish it. In the case of swapping Fragments in a single Activity, well the Activity is still accessible by both Fragments, and all your message passing can simply go through the Activity.

请记住,您始终在 Fragment 与其 Activity 之间进行通信.以结果开始和结束是活动之间通信的机制——活动然后可以将任何必要的信息委托给它们的片段.

Just remember that you always have communication between a Fragment and its Activity. Starting for and finishing with a result is the mechanism for communication between Activities - The Activities can then delegate any necessary information to their Fragments.

这篇关于有没有一种方法可以像开始片段的结果一样工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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