Android的:如何使用从母体传递活动中的数据子活动? [英] Android: how to use data passed from parent activity in a sub activity?
问题描述
大家好 当我们想从一个活动传递数据,我们使用
Hi all When we want to pass data from an activity to a sub activity we use the
intent.pushextra()
方法,并传递请求code和任何其他数据。
method and pass the request code and any additional data.
现在的子活动我怎么可以得到额外的数据,或者请求code。
now in the subactivity how can I get the additional data or the request code.
有没有处理这个任何事件处理?
is there any event handler that handles this ?
感谢
推荐答案
您使用 intent.putExtra()
将数据的意图,然后在子活动的的onCreate()
使用 getIntent()。getExtras()
或 getIntent()。getXXXExtra()
的方法。
You use intent.putExtra()
to put data in the intent, then in the sub activity's onCreate()
use getIntent().getExtras()
or getIntent().getXXXExtra()
methods.
例如,用于检索一个字符串,你可以使用:<一href="http://developer.android.com/reference/android/content/Intent.html#getStringExtra%28java.lang.String%29"相对=nofollow> getStringExtra()
For example for retrieving a String you would use: getStringExtra()
这篇关于Android的:如何使用从母体传递活动中的数据子活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!