[英]How to send data to new activity from current activity via intent?
How I can use the intent to send the data to the second class? 如何使用意图将数据发送给第二类?
I am doing this actually 我实际上是在这样做
Intent connectGetData = new Intent(Main.this, GetData.class);
startActivityForResult(connectGetData, REQUEST_GET_DATA);
From Main.java
activity I am calling the Getdata.java
activity and I when come back I again get data using. 从
Main.java
活动中,我正在调用Getdata.java
活动,当我回来时,我再次使用了数据。
public void onActivityResult(int mRequestCode, int mResultCode, Intent mDataIntent)
Please tell me how I can send data to other activity 请告诉我如何将数据发送到其他活动
You pass data along with the Intent using two mechanisms, depending on the needs of your application. 您可以使用两种机制将数据与Intent一起传递,具体取决于应用程序的需求。
Intent.setData()
: This is a URI that you can use to indicate the location of a resource the new Activity may need to use Intent.setData()
:这是一个URI,可用于指示新Activity可能需要使用的资源的位置 Intent.putExtra()
: You can attach as many extras to an Intent as you like to represent the data you need to pass (both forwards to the new Activity and backwards with the result). Intent.putExtra()
附加功能:您可以将任意多个附加附加到Intent,以表示您需要传递的数据(既向前传递到新的Activity,又向后传递结果)。 Extras can be any primitive or easily serializable object. HTH 高温超导
At sending activity... 正在发送活动...
Intent intent = new Intent(current.this, next.class);
intent.putextra("keyName","value");
startActivity(intent);
At receiving activity... 在接受活动时...
String data = getIntent().getExtras().getString("keyName");
Thus you can have data at receiving activity from sending activity... 因此,您可以从发送活动的接收活动中获得数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.