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");   //获取传递过来的数据

相关内容

热门资讯

新手必备!wepoker分析,... 新手必备!wepoker分析,wepoker黑侠破解,透明教程(有挂透明);wepoker黑侠破解软...
信息共享!德扑HHpoker有... 信息共享!德扑HHpoker有挂吗,约局吧辅助器,攻略方法(有挂神器)科技教程也叫必备教程,这是一款...
总算清楚!hhpoker怎么破... 总算清楚!hhpoker怎么破解,aapoker ai插件,实用技巧(有挂教程);致您一封信;亲爱h...
重大通报!xpoker怎么作弊... 重大通报!xpoker怎么作弊,wepoker好友局透视,第三方教程(有挂教程);支持2-10人实时...
玩家必看科普!wepoker手... 玩家必看科普!wepoker手机助手,拱趴大菠萝辅助神器,辅助教程(有挂透视);人气非常高,ai更新...
发现一款!wepoker有透视... 发现一款!wepoker有透视吗,德州透视竞技联盟,新2025教程(有挂透视);玩家必备必赢加哟《1...
攻略讲解!wepoker私人局... 攻略讲解!wepoker私人局规律,hhpoker透视工具,安装教程(有挂透明);实战中需综合运用上...
教程攻略!德普之星有辅助软件吗... 教程攻略!德普之星有辅助软件吗,wepoker永久免费脚本,系统教程(有挂神器);科技安装教程;13...
重大通报!hhpoker免费透... 重大通报!hhpoker免费透视脚本,pokermaster破解版,黑科技教程(有挂神器);玩家必备...
一分钟教你!wpk官网下载链接... 一分钟教你!wpk官网下载链接,pokeplus脚本,透明挂教程(有挂透明)关于wpk官网下载链接机...