我有 2 项活动涉及这个问题。第一个是用户在简单的表单样式布局上输入数据。然后它应该将 4 条数据保存到一个意图 (putextra) 和 startActivity(intent)。
第二个应该检索数据并准备好将它们加载到数组中。当我运行调试时,来自 activity1 的意图成功地保存了这些值;但是,activity2 说意图是空的。我不确定两者之间发生了什么。
活动1
EditText editDebtName = (EditText) findViewById(R.id.dispDebtName);
debtName = editDebtName.getText().toString();
EditText editDebtAmount = (EditText) findViewById(R.id.dispDebtAmount);
String debtAmountStr = editDebtAmount.getText().toString();
EditText editDebtRate = (EditText) findViewById(R.id.dispDebtRate);
String debtRateStr = editDebtRate.getText().toString();
EditText editDebtPayment = (EditText) findViewById(R.id.dispDebtPayment);
String debtPaymentStr = editDebtPayment.getText().toString();
Intent i = new Intent(this, DebtList.class);
i.putExtra("newDebtName", debtName);
i.putExtra("newDebtAmount", debtAmountStr);
i.putExtra("newDebtRate", debtRateStr);
i.putExtra("newDebtPayment", debtPaymentStr);
startActivity(i);
活动2
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.debtlist);
String[] debtName = new String[10];
String[] debtAmount = new String[10];
String[] debtRate = new String[10];
String[] debtPayment = new String[10];
int trigger = 5;
SharedPreferences sharedPref= getSharedPreferences("chaosdatasnowball", 0);
debtName = getFromSharedPreference("debtNames", this.getApplicationContext());
debtAmount = getFromSharedPreference("debtAmounts", this.getApplicationContext());
debtRate = getFromSharedPreference("debtRates", this.getApplicationContext());
debtPayment = getFromSharedPreference("debtPayments", this.getApplicationContext());
trigger = sharedPref.getInt("trigger", trigger);
Bundle extras = getIntent().getExtras();
debtName[trigger] = extras.getString("newDebtName");
debtAmount[trigger] = extras.getString("newDebtAmount");
debtRate[trigger] = extras.getString("newDebtRate");
debtPayment[trigger] = extras.getString("newDebtPayment");
也没有错误消息被抛出。我要确定的是..为什么没有收到我的意图..?