-2

How to pass an intent with parameters? Neither array nor bundles are working.

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

Receiving code

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

Using bundles

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

Receiving side

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");
Adinia
  • 3,722
  • 5
  • 40
  • 58
Coder
  • 17
  • 2

1 Answers1

0

First make String type of ArrayList like this

 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;
}

After that send this ArrayList via intent

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

Catch it like this in another activity

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

after that you can get your values from ArrayList

Sohel S9
  • 246
  • 1
  • 15