如何从当前的活动意图,通过将数据发送到新的活动? [英] How to send data to new activity from current activity via intent?

查看:96
本文介绍了如何从当前的活动意图,通过将数据发送到新的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用的意图,将数据发送到第二类?

How I can use the intent to send the data to the second class?

我这样做实际上

Intent connectGetData = new Intent(Main.this, GetData.class);
startActivityForResult(connectGetData, REQUEST_GET_DATA); 

Main.java 的活动我打电话了 Getdata.java 的活动,我回来的时候,我再次得到使用数据。

From Main.java activity I am calling the Getdata.java activity and I when come back I again get data using.

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.

  1. 在数据字段,通过 Intent.setData():这是一个URI,你可以用它来说明资源的新的活动可能需要使用的位置
  2. 附加功能,通过 Intent.putExtra():只要你喜欢重新present你需要传递的数据(你可以将尽可能多的群众演员的意图两者转发到新的活动和向后的结果)。附加功能可以是任何原始的或容易序列化对象。
  1. The data field, via Intent.setData(): This is a URI that you can use to indicate the location of a resource the new Activity may need to use
  2. Extras, via 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). Extras can be any primitive or easily serializable object.

心连心

这篇关于如何从当前的活动意图,通过将数据发送到新的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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