向后将数据发送到previous活动 [英] Send data backwards to a previous activity

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

问题描述

我想在向后将数据发送到活动已在运行一些帮助。

I would like some help in sending data backwards to an Activity that is already running.

我希望用户能够从列表中选择一个选项,然后在previous的活动,选择使用。我知道怎么做了前进使用意图,但不能看到如何将工作在这种情况下,无需任意数量的同一活动窗口在同一时间运行。

I want the user to be able to select an option from a list and then that selection be used in a previous activity. I know how to do it going forward using intents but can't see how that would work in this case without having an arbitrary number of the same activity windows running at the same time.

有点像在电话中更改设置,但更多的有机会获得一个字符串。如果您需要更多的信息,只问。

Sort of like changing the settings within the phone but more having access to a string. If you need any more information just ask.

推荐答案

有两种方法可以做到这一点,首先是而不是调用startActivity()调用startActivityForResult(),这是该文档有什么看法

There are two ways to do this, the first is rather than calling startActivity(), call startActivityForResult(), this is what the documentation has to say about it:

有时候,你想让它结束时得到的结果,从一个活动回来。例如,你可以开始一个活动,让用户选择一个人在联系人列表;它结束时,它返回所选择的人。要做到这一点,你叫startActivityForResult(意向,INT)版采用了第二个整数参数识别呼叫。其结果会通过您的onActivityResult(INT,INT,意图)方法。

Sometimes you want to get a result back from an activity when it ends. For example, you may start an activity that lets the user pick a person in a list of contacts; when it ends, it returns the person that was selected. To do this, you call the startActivityForResult(Intent, int) version with a second integer parameter identifying the call. The result will come back through your onActivityResult(int, int, Intent) method.

<一个href="http://developer.android.com/reference/android/app/Activity.html">http://developer.android.com/reference/android/app/Activity.html

另一种方式来做到这一点是发送一个广播,在你的活动结束,并注册一个BroadcastReceiver()在你原来的活动。

The other way to do it is to send out a broadcast at the end of your activity, and register a broadcastReceiver() in your original activity.

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

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