Android的:如何来传递数据给子活动? [英] Android: How to pass the data to sub-activities?

查看:106
本文介绍了Android的:如何来传递数据给子活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要活动包括与设定值的一些变量。我创建与具有被填充有来自主活动的数据,所以我想数据必须被传递到子活动启动时的形式的子活动

The main activity includes some variables with set values. I created a sub-activity with the form which has to be filled with the data from main activity so I guess the data have to be passed to the sub-activity when it starts.

有谁知道如何从主要活动传递变量值的子活动?

Does anyone know how to pass the variable values to the sub-activity from the main activity?

谢谢!

推荐答案

您可以在您的主要活动使用此方法

You can use this method in your main activity

Intent i = new Intent(this, YourMainClass.class);
i.putExtra("key", value);

结束,然后在子活动得到这种方法的价值,一般在onCreate事件

end then in the sub activity get the value with this method, usually in the onCreate event

int value = getIntent().getExtras().getInt("key");

我希望这hepls。

I hope this hepls.

这篇关于Android的:如何来传递数据给子活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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