我正在尝试将字符串从一个活动传递到另一个活动。我似乎无法从意图中获得额外的东西。我哪里错了?
以下是代码
要将额外的内容放入意图中:
public void onClick(View v) {
// TODO Auto-generated method stub
String string = editTextFeild.getText().toString();
Intent i = new Intent("com.com.com.otherclass");
i.putExtra("dat", string);
startActivity(new Intent("com.com.com.otherclass"));
}要从intent获取数据(在com.otherclass中):
Bundle bundle = getIntent().getExtras();
if (bundle != null){
String string = bundle.getString("dat");
textView.setText(string);
}附注:这些不是我在代码中使用的实际名称:)
提前感谢:)
发布于 2012-09-09 12:50:10
在您的startActivity行中,您正在创建一个新的意图。改为传递“i”。
startActivity(i);发布于 2012-09-09 13:28:35
要将任何数据或字符串发布到其他活动,只需将以下几行代码放在一个变量中,这些代码将把您的数据传输到其他活动中
Intent itemintent = new Intent(this, ShowDescription.class);
Bundle b = new Bundle();
b.putInt("position", position);
b.putStringArray("title_s", title_s);
b.putStringArray("desc_s", desc_s);
b.putStringArray("link_s", link_s);
itemintent.putExtra("android.intent.extra.INTENT", b);
startActivity(itemintent);这会将您的数据提交到其他Activity Showdescription.java类
您可以通过以下方法获取数据。
Bundle b = startingIntent.getBundleExtra("android.intent.extra.INTENT");
title_s = b.getStringArray("title_s");
desc_s = b.getStringArray("desc_s");
link_s = b.getStringArray("link_s");
pub_s = b.getStringArray("position");这将获取数据。有关获取数据的更多信息,请参阅以下链接http://grabcodes.blogspot.in/2012/08/passing-data-between-two-activities.html
https://stackoverflow.com/questions/12336510
复制相似问题