从活动到B活性路过的数据再回到活动 [英] Passing data from activity a to activity b then back to activity a

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

问题描述

我想问一下如何从到活动B片段的传递值,则回片段。我试着用束传递价值,但它会给错误的数据。

I would like to ask how to pass value from fragment a to activity B then back to the fragment. i tried using bundle to pass the value but it will give the wrong data.

感谢您。

推荐答案

如果您想从活动B的数据发送到酶活性的使用code

If you want to send the data from activity B to activity A use the code

在活动B

Intent intent = new Intent ();
intent.putExtra ("string_1", "hello");
intent.putExtra ("string_2", "world");
intent.putExtra ("int_1", 1000);
intent.putExtra ("long_1", 2000l);
activity.setResult (Activity.RESULT_OK, intent);
finish()

因此​​,在活动A code将

So in Activity A code will be

@Override
protected void onActivityResult (int requestCode, int resultCode, Intent intent)
{
    if (resultCode == Activity.RESULT_OK)
    {
        String string_1 = intent.getStringExtra ("string_1", "");
        String string_2 = intent.getStringExtra ("string_2", "");
        int int_1 = intent.getIntExtra ("int_1", 0);
        long long_1 = intent.getLongExtra ("long_1", 0);
    }
}

所以,现在你得到了在A.数据
因此,通过使用在片段中定义的方法可以将数据发送到目的片段

So now you got the data in A. So by using the method defined in fragment you can send the data to the target fragment

喜欢说

在片段,如果你定义

public void refreshFragment(String s1)  {

// here s1 will be the data you send from activity Q
}

希望这有助于

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

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