AndroidStudio中向其他Activity发送数据的问题。
创始人
2024-08-21 08:30:05
0
  1. 通过Intent来传递数据。创建发送者的Intent对象,使用putExtra()方法将需要传递的数据放入intent中,然后使用startActivity()方法启动接收数据的Activity。

发送方代码示例:

Intent intent = new Intent(SenderActivity.this, ReceiverActivity.class);
intent.putExtra("key", "value");   //将需要传递的数据放入intent中
startActivity(intent);

接收方代码示例:

Intent intent = getIntent();   //获取intent对象
String data = intent.getStringExtra("key");   //获取传递过来的数据
  1. 通过Bundle来传递数据。将需要传递的数据放入Bundle对象中,将Bundle对象放入Intent中,然后启动接收数据的Activity。

发送方代码示例:

Intent intent = new Intent(SenderActivity.this, ReceiverActivity.class);
Bundle bundle = new Bundle();
bundle.putString("key", "value");   //将需要传递的数据放入bundle中
intent.putExtras(bundle);   //将bundle放入intent中
startActivity(intent);

接收方代码示例:

Intent intent = getIntent();
Bundle bundle = intent.getExtras();   //获取传递过来的Bundle对象
String data = bundle.getString("key");   //获取传递过来的数据

相关内容

热门资讯

热点讨论!安装不了wepoke... 热点讨论!安装不了wepoker,哈糖大菠萝能开挂吗,科技教程(有挂神器);亲真的是有正版授权,小编...
热点推荐!哈糖大菠萝助手,智星... 热点推荐!哈糖大菠萝助手,智星德州插件最新版本更新内容详解,透牌教程(有挂软件)1、点击下载安装,微...
一分钟揭秘!wepokerpl... 自定义wepoker有透视功能吗系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅...
一分钟揭秘!wepoker怎么... 一分钟揭秘!wepoker怎么挂底牌,德州hhpoker脚本,科技教程(有挂方法);科技安装教程;1...
攻略讲解!wepoker有什么... 攻略讲解!wepoker有什么规律,约局吧德州真的存在透视吗,技巧教程(有挂技巧)是一款可以让一直输...
科技分享!微扑克微乐辅助,佛手... 科技分享!微扑克微乐辅助,佛手大菠萝13道挂哪里,详细教程(有挂软件)1、玩家可以在佛手大菠萝13道...
重大推荐!poker worl... 这是一款非常优秀的wepoker网页版透视方法 ia辅助检测软件,能够让你了解到wepoker网页版...
热点讨论!拱趴大菠萝挂怎么安装... 热点讨论!拱趴大菠萝挂怎么安装,wepoker黑侠破解,AI教程(有挂方法)1、玩家可以在拱趴大菠萝...
我来向大家传授!aapoker... 我来向大家传授!aapoker破解侠是真的吗,wepokerplus作弊,玩家教你(有挂神器)1、玩...
玩家必用!德州局怎么透视,we... 1、玩家必用!德州局怎么透视,wepoker免费透视脚本,2025新版教程(有挂技巧)。2、wepo...