我不能传递意图,既不能使用数组也不能通过bundle传递



如何使用参数传递意图?阵列和束都无法正常工作。

Intent intent = new Intent(Apply_leave_Activity.this, ApplyingReason_Activity.class);
intent.putExtra("ID_EXTRA", new String[] { "21",countOfCL,countOfSL ,countOfEL,startDatey,endDatey,currentDatey});
startActivity(intent);

接收代码

 String x[]=new String[10];
 x  =getIntent().getStringArrayExtra("ID_EXTRA");

使用捆绑包

Bundle extras = new Bundle();
  extras.putString("EID", "21");
  extras.putString("countOfCL", countOfCL);
  extras.putString("countOfSL", countOfSL);
  extras.putString("countOfEL", countOfEL);
  extras.putString("From_date", startDatey);
  extras.putString("To_date", endDatey);
  extras.putString("applied_date", currentDatey);
 intent.putExtras(extras);
 startActivity(intent);

接收方

Intent intent = getIntent();
Bundle extras = intent.getExtras();
      final   String EID = extras.getString("EID");
      final String numberOfCasualLeaves = extras.getString("countOfCL");
      final   String numberOfsickLeaves = extras.getString("countOfSL");
      final String numberOfearnedLeaves = extras.getString("countOfEL");
      final String from_date = extras.getString("From_date");
      final String to_Date = extras.getString("To_date");
      final String applied_date = extras.getString("applied_date");

首先将字符串类型的arraylist类型

 public ArrayList<String> getArrayList() {
    ArrayList<String> list = new ArrayList<>();
    list.add("21");
    list.add(countOfCL);
    list.add(countOfSL);
    list.add(countOfEL);
    list.add(startDatey);
    list.add(endDatey);
    list.add(currentDatey);
    return list;
}

之后通过意图发送此arraylist

    Intent intent = new Intent(this, ApplyingReason_Activity.class);
    intent.putStringArrayListExtra("key", getArrayList());
    startActivity(intent);

在另一个活动中这样捕捉

     Intent i = getIntent();
    ArrayList<String> list = i.getStringArrayListExtra("key");

之后,您可以从arraylist

获得值

最新更新