How to pass integer arrays in Android from one activity to a fragment by value? Whenever I pass an array using Bundle
or Intent
to pass to another activity, it seems that it is passed by reference.
I am passing an array from a fragment to an activity where I pass it to 2 functions which sorts the array using 2 different algorithms. However, the 2nd sorting algorithm gets a sorted array because the 1st algorithm has already sorted it before. I need that both function calls have the same input array.
int[] inputArray = getIntent().getIntArrayExtra("input")
bubbleSort(inputArray);
mergeSort(inputArray);
Even if I make a copy of the array it doesn't work because probably the array was passed by reference.