无法将值从一个活动发送到Android中的其他活动
问题描述:
我创建了一个包并将值放到它上面并跳到下一个活动,出于某种原因它无法在另一端获取值,它说空对象的引用,但我有我的价值观和我在一起,无法将值从一个活动发送到Android中的其他活动
public void rsa_key(String s){
Intent intent = new Intent(getBaseContext(), SomeClass.class);
//Create the bundle
Bundle bundle = new Bundle();
//Add your data to bundle
//String hello=null;
bundle.putString("id", txId);
bundle.putString("cardamt", cardAmount);
bundle.putString("cardconv", cardConvFee);
//Add the bundle to the intent
intent.putExtras(bundle);
startActivity(intent);
}
在其他活动
String txId = bundle.getString("id");
String cardConvFee = bundle.getString("cardconv");
String cardAmount = bundle.getString("cardamt");
答
试试这个:
public void rsa_key(String s){
Intent intent = new Intent(getBaseContext(), SomeClass.class);
//String hello=null;
intent.putExtras("id", txId);
intent.putExtras("cardamt", cardAmount);
intent.putExtras("cardconv", cardConvFee);
startActivity(intent);
}
在你的第二个活动onCreate方法
答
请先整数转换值的字符串,然后将其发送到另一个活动。
Bundle bundle = new Bundle();
//Add your data to bundle
//String hello=null;
bundle.putString("id", String.valueOf(txId));
bundle.putString("cardamt", String.valueOf(cardAmount));
bundle.putString("cardconv", String.valueOf(cardConvFee));
你在哪里有其他活动的代码。在onCreate。另外使用调试器应该会有所帮助 – Raghunandan
你如何获得第二项活动中的第一项活动?请张贴您的日志。 –
我已经把它放在OnCreate之外,我猜这就是问题 – Venky