Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

New Forums: Nexus Player | Nexus 9
test: Reply
 
LinkBack Thread Tools
Old December 4th, 2012, 01:43 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Oct 2012
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Saving values from a (Float) ArrayList into a Bundle

I'm writing a game using Surfaceview and have a question relating to saving Data into a Bundle.

Initially, I had an arraylist which stored the Y co-ordinates (in the form of Integers) of sprites that will move only up and down. Declared as:

Quote:
static ArrayList<Integer> ycoordinates = new ArrayList<Integer>();
I saved them to a Bundle using the following:

Quote:
myBundle.putIntegerArrayList("myycoordinates", ycoordinates);
And restored them using this:

Quote:
ycoordinates.addAll(savedState.getIntegerArrayList ("ycoordinates"));
This all worked perfectly. However, I've had to change the whole coordinates system so it's based on Delta time to allow my sprites to move at a uniform speed across different screens. This is, again, working perfectly.

However, as a result of this change, I now have to store these values as floats rather than integers.

So, I am declaring as:

Quote:
static ArrayList<Float> ycoordinates = new ArrayList<Float>();
So that's the background, now my question is, how do I store and restore values from a Float Arraylist? There doesn't seem to be a "putFloatArrayList" or "getFloatArrayList".

(I've used an Arraylist rather than an Array as the number of sprites needs to be dynamic).

Any help would be appreciated.

Many thanks

Advertisements
droidzip is offline  
Reply With Quote
sponsored links
Old December 5th, 2012, 04:18 PM   #2 (permalink)
Junior Member
 
Join Date: May 2012
Posts: 27
 
Device(s): Nexus 7 (Android 4.2.1), Samsung Galaxy Mini (Android 2.3.6)
Carrier: Not Provided

Thanks: 1
Thanked 2 Times in 2 Posts
Default

You can either convert the list to an array, put it in the bundle using putFloatArray and than after getting it convert it back to a list. Or you can use putSerializable and getSerializable.
myrecek is offline  
Reply With Quote
Reply
Tags
array, arraylist, bundle, onsaveinstancestate


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 01:59 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.