How do you pass a float[] array between activities in android?

If I understand your question correctly, there are two (maybe more) ways: 1) Pass the float in the constructor of class2. (Given your code, this probably isn't the best way. ) 2) Create a method setMyFloatArray(float arr) in class2 and a getMyFloatArray() method in class1.

After instantiating class1 and class2 in your program, call the set method with the get method as the argument.

Neither of these will work in android – Falmarri Nov 12 '10 at 17:05.

It seems that this is more difficult than first appearances as it's not a java problem but an android problem. See here for more information.

(note - I edited my answer with more android specific pointers) – KevinDTimm Nov 12 '10 at 17:13 the link you have in the edit does contain the correct answer. The part you have before that does't realy make any sense in the Android setting. – Mayra Nov 12 '10 at 18:00 @Mayra - fixed, thank you.

– KevinDTimm Nov 12 '10 at 19:03.

For that you may use String extras passed along with the Intent. So, first of all you need to get a String representation of your float array: public class YourArrayUtils { public static String pack(float data) { StringBuilder sb = new StringBuilder(); final int length = data. Length; for (int I = 0; I Append(datai); if (i Split(str, ":"); final int length = srtData.

Length; float result = new floatlength; for (int I = 0; I This, YourActivityB. Class); i. PutExtra("floatArray", YourArrayUtils.

Pack(yourFloatArray)); startActivity(i); And finally in YourActivityB extract it: @Override protected void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); ... Intent I = getIntent(); // get starting Intent float yourFloatArray = YourArrayUtils. Unpack(i.

GetStringExtra("floatArray")); ...

You can pass data around in a Global Singleton if it is going to be used a lot. Public class YourApplication extends Application { public float points = new float100; } Then call it in any activity by: YourApplication appState = ((YourApplication)this.getApplication()); appState. Points = new float100; // Do whatever you need to with the points here.

That seems like a really bad idea.At the very minimum you should use a getter, in case you someday want to change that array to a list, or something else. – Mayra Nov 12 '10 at 18:38 @Mayra it was merely an example of how to access a global singleton, the implementation is up to the reader. I condensed it for the sake of readability.It is better to setup a class as the global object that has yes, accessor and setters.

For a more clearcut example, see my blog post here, heading "Global Singletons" bryandenny. Com/index. Php/2010/05/25/… You can't pass such complex data via intents, so you have to do this or use a database or similar.

– Bryan Denny Nov 12 '10 at 18:54.

Resulti = Float. Intent I = new Intent(YourActivityA. Float yourFloatArray = YourArrayUtils.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions