Sending arrays with Intent.putExtra Sending arrays with Intent.putExtra android android

Sending arrays with Intent.putExtra


You are setting the extra with an array. You are then trying to get a single int.

Your code should be:

int[] arrayB = extras.getIntArray("numbers");


This code sends array of integer values

Initialize array List

List<Integer> test = new ArrayList<Integer>();

Add values to array List

test.add(1);test.add(2);test.add(3);Intent intent=new Intent(this, targetActivty.class);

Send the array list values to target activity

intent.putIntegerArrayListExtra("test", (ArrayList<Integer>) test);startActivity(intent);

here you get values on targetActivty

Intent intent=getIntent();ArrayList<String> test = intent.getStringArrayListExtra("test");


final static String EXTRA_MESSAGE = "edit.list.message";Context context;public void onClick (View view){       Intent intent = new Intent(this,display.class);    RelativeLayout relativeLayout = (RelativeLayout) view.getParent();    TextView textView = (TextView) relativeLayout.findViewById(R.id.textView1);    String message = textView.getText().toString();    intent.putExtra(EXTRA_MESSAGE,message);    startActivity(intent);}