距离新活动将数据传递到老年活动? [英] Passing data from New activity to old activity?

查看:148
本文介绍了距离新活动将数据传递到老年活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想接受新的活动数据,以旧的活动。

I am trying to receive data from new Activity to old Activity.

在换句话说,新的活动必须发送准备数据,老年活动,当它完成。

In other words, newer Activity must send intend data to old activity when it finishes.

我已经使用的setResult(结果code,NewActivity.this.getIntend); 较新的活动和

I've use setResult(resultcode, NewActivity.this.getIntend); on newer activity and

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(data != null) {
        // doing something
    }     
}

在原有的业务。收到新的活动打算数据。

on old activity. Receives intend data from newer activity.

但是,这code不起作用。始终让数据为空。

But this code doesn't work. Always getting data is null.

如何从整理活动于母公司活动发送意图数据?

How to send intent data from finishing Activity to parent activity ?

此外,当创建新的活动,我使用下面的code:

Also when create new Activity, I am using following code:

Intent intent = new Intent(Intent.ACTION_PICK);
intent.setClass(OldActivty.this, NewActivity.class);
startActivityForResult(intent, 0);

我不明白为什么总是从较新的获取空意图数据。

I don't understand why always getting null intent data from newer one.

如何解决?

请指教。

谢谢

推荐答案

由于CommonsWare写在他的评论您传递相同的意图回到你的活动,你用来启动活动。

As CommonsWare wrote in his comment you are passing the same Intent back to your Activity that you used to start the Activity.

尝试像下面code:

Intent newIntent = new Intent();
newIntent.putExtra(key, yourData)
newIntent.putExtra(key2, moreData)

setResult(resultcode, newIntent);

在你的情况下,意图是只需要存储传回的数据。因此,你可以使用标准的构造函数。

In your case the Intent is only needed to store the data that is passed back. Therefor you can use the standard constructor.

这篇关于距离新活动将数据传递到老年活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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