无法将值从一个 activity 发送到 Android 中的另一个
unable to send values from one activity to other in Android
我创建了一个包并将值放入其中并跳转到下一个 activity,由于某种原因它无法在另一端获取值,它说空对象引用,但我有我的价值观,
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);
}
在其他activity
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);
}
在您的第二个 activity onCreate 方法中
Bundle bundle = getIntent().getExtras();
String txId = bundle.getString("id");
String cardConvFee = bundle.getString("cardconv");
String cardAmount = bundle.getString("cardamt");
请先转换字符串中的整数值,然后再将其发送给另一个activity。
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));
我创建了一个包并将值放入其中并跳转到下一个 activity,由于某种原因它无法在另一端获取值,它说空对象引用,但我有我的价值观,
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);
}
在其他activity
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);
}
在您的第二个 activity onCreate 方法中
Bundle bundle = getIntent().getExtras();
String txId = bundle.getString("id");
String cardConvFee = bundle.getString("cardconv");
String cardAmount = bundle.getString("cardamt");
请先转换字符串中的整数值,然后再将其发送给另一个activity。
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));