可能重复: 如何在Android中的活动之间传递数据?
我的应用程序中有三个活动,每个活动都取决于另一个活动。我目前正在使用静态变量在这些活动之间传递对象和值。这方面的问题是,它会变得非常混乱,而且很难跟踪我何时分配给全局变量一个值等等。我正在考虑在这些活动之间实现一个接口,以使代码更清晰、更容易理解。问题是,我不完全确定这是最好的方式,所以任何帮助或建议都会很好。
发布于 2012-03-13 10:25:25
使用putExtra向其他活动发送信息
发送:
Bundle bundle = new Bundle();
bundle.putString(“name″, “username”);
Intent newIntent = new Intent(this.getApplicationContext(), ActivityClass2.class);
newIntent.putExtras(bundle);
startActivityForResult(newIntent, 0);接收:
Bundle bundle = this.getIntent().getExtras();
String data = bundle.getString(“name″);data =用户名
发布于 2012-03-13 10:25:22
我相信您想要的是Intent.putExtra()方法。有几种方法取决于您想要传递的数据类型。请参阅文档化这里。
发布于 2012-03-13 10:26:40
传送资料:-
Intent i = new Intent();
i.putExtra("key", "data");
startActivity(i);https://stackoverflow.com/questions/9682167
复制相似问题