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

相关内容

热门资讯

透视关于"红龙pok... 透视关于"红龙poker有辅助吗"总是是有辅助神器(哔哩哔哩)1、进入到红龙poker有辅助吗是否有...
透视普及"poker... 您好,pokernow辅助工具这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302...
透视详细"红龙pok... 透视详细"红龙poker辅助平台"都是有辅助挂(哔哩哔哩)1、全新机制【红龙poker辅助平台ai辅...
透视开挂"cloud... 透视开挂"cloudpoker怎么开挂"本来存在有辅助工具(哔哩哔哩)1、下载好cloudpoker...
透视辅助"wepok... 透视辅助"wepoker私局辅助"都是真的有辅助工具(哔哩哔哩)wepoker私局辅助辅助器是一种具...
透视教你"wepok... 透视教你"wepoker开辅助能查到吗"总是真的是有辅助app(哔哩哔哩)运wepoker开辅助能查...
透视了解"sohoo... 透视了解"sohoo开挂辅助"一贯真的是有辅助app(哔哩哔哩)进入游戏-大厅左侧-新手福利-激活码...
透视揭幕"aapok... 透视揭幕"aapoker安装包怎么使用"都是是真的辅助神器(哔哩哔哩)1)aapoker安装包怎么使...
透视曝光"wepok... 透视曝光"wepoker辅助器是真的吗"果然真的是有辅助攻略(哔哩哔哩)1、首先打开wepoker辅...
透视曝光"xpoke... 透视曝光"xpoker辅助控制"一贯真的有辅助工具(哔哩哔哩)1、全新机制【xpoker辅助控制ai...