没有收到意图

时间:2013-11-08 02:41:07

标签: android android-intent

我有2个活动涉及这个问题。第一个用户在简单的表单样式布局上输入数据。然后它应该将4个数据保存到intent(putextra)和startActivity(intent)。

第二个应该检索数据并准备好将它们加载到数组中。当我运行调试时,来自activity1的intent成功保存了值;但是,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");

也没有丢失错误消息。我想要确定的是......为什么我的意图没有被收到..?

1 个答案:

答案 0 :(得分:1)

我认为这个问题引起的问题

    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());

因为我测试没有上面的代码,activity2仍然收到bundle值。如果你尝试没有上面的代码,仍然有这个问题,你应该尝试调试&显示字符串数组的所有值以再次确定问题。