I make and Android App in Android Studio, and I have some problems with passing Float array from one Activity to another (I wanna pass this array and make a chart with MPAndroidChart). I found here how to pass a String Array (using Java) and tried to do the same with Float array (using Kotlin), but Android Studio returns an error. Please show how to pass the Float array to another Activity right, putFloatArrayExtra function doesn’t work in my project
I tried to use this code:
var b = Bundle();
b.putStringArray("key", myArray);
Intent i=new Intent(this, ChartActivity::class.java);
i.putExtras(b);
and this:
var b: Bundle = this.getIntent().getExtras();
var array=b.getStringArray(key);
2
Answers
You have to use Intent#putExtra(String name, @Nullable float[] value) to put float array to the extras.
And in your second Activity get this array using Intent#getFloatArrayExtra(String name):
To pass an array from one intent to another in Kotlin for Android, you can follow this approach:
In the first activity, declare and initialize the float array, Then create an intent and add the float array as an extra:
In the second activity, retrieve the float array from the intent: