Saving Values From (Float) ArrayList Into A Bundle

Dec 4, 2012

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).

Saving values from (Float) ArrayList into a Bundle


Android :: Way To Send ArrayList Of Custom Objects In Bundle?

Sep 16, 2010

I have an application that uses a service to create an ArrayList of custom objects (MyObject) every x seconds. I then want my Activity to obtain this ArrayList. I'm currently planning on having the Service send a message to the Activity's handler every time it finishes the query for the data. I want the message to the Handler to contain the ArrayList of MyObjects. When building the method in the Activity to get this ArrayList out of the message, I noticed that I couldn't.

View 1 Replies View Related

Android :: Saving State Of ArrayList Of Custom Objects

Aug 12, 2010

I have a member variable in my Activity which is an ArrayList. The objects populating this Array List are objects I have defined called Rating Item. Rating Item has several member vars like rating, comment, ID, etc. I would like to save this Array List in onSaveInstanceState so it can be repopulated from onRestoreInstanceState. What is the best way to do this? I've never saved the state of an object of this complexity.

View 2 Replies View Related

Android :: Saving ArrayList Of User Defined Objects

Aug 10, 2010

I am working on an application where I am saving the state of an application in an ArrayList. Now, to save this state, I tried to use Serialization. But, somewhere in the user defined object, I am using Button, which is not letting me serialize the entire object. I wanted to know, is there any other way of saving this array list between onPause and onResume? I even tried onSaveInstanceState, but it doesn't have support for Array List.

View 1 Replies View Related

Android :: Saving ArrayList To Txt File / Data Folder Empty

Apr 25, 2010

I am trying to save an arraylist to a .txt file below is the code I am using, which runs without error but when I try to go to Astro file manager and browse the data folder there is nothing there.

String filename = stationname.getText().toString() + System.currentTimeMillis();
FileOutputStream fos = openFileOutput(filename,Context.MODE_PRIVATE);
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject(report);
Report is the ArrayList that holds each of my station Reports.
out.close();

View 15 Replies View Related

Android :: Saving An ArrayList (String) State In SQLite Database

Jul 9, 2010

I'm working on a android application that will display Strings to the user, and the user then has the option to add one to a favorite list. I have searched and searched and cannot find the proper way of doing this. I did get one open source project, everything worked until the user removed a favorite. The database would clear the row of data, but when a new row is added, it would behave as if the deleted row still had data, leaving blanks in the favorite list.

This is my insert method
public long insertString(String newString)
ContentValues newStringValue = new ContentValues();
newStringValue.put(KEY_STRING, newString);
return db.insert(DATABASE_TABLE, null, newStringValue);

The long returned will always increment even if i use the remove method:
public boolean removeString(long _rowIndex)
return db.delete(DATABASE_TABLE, KEY_ID + "=" + _rowIndex, null) > 0;

If I try to remove the third index, and the user removed a question at the third index, the method returns false, is there a way to completely remove all rows with no data?

View 2 Replies View Related

Android :: Switching Views With RadioButton And Saving Views In Bundle

Mar 6, 2010

I have the following XML code:.................

The idea is to change the views, whenever I press one of the radio buttons. When I press a button the first time everything works out fine, but the second time I press a button, I get an IllegalStateException, and I can't quite see why I'm getting this.

Also, the Activity seems to set all my global variables to null, which is why I have to create them every time I switch from portrait to landscape or vice versa. So I would like to know if there is a way I can save my views in the Bundle, or any other way in which I can permanently save my views, so I don't have to add or create them every time, I flip the phone. And whenever I flip the phone, it seems that it rereads the main XML file, causing the RadioGroup to be set to 2D even if the 3D button is checked. This is because I've said the 2D button to be checked from when the app is first created, but I would like to also save the state of that RadioGroup.

View 5 Replies View Related

Android :: Saving ArrayList In SQLite Database In Android

Jun 29, 2010

I've been working with SQLite on android and I would like to add an arraylist to a column in a table, and then fetch the data back as an arraylist. The arraylist is a list of Longs. I've noticed that SQL has an option for storing BLOBS, however, it looks like I need to convert the array list to a byte[] first before being able to store it as a blob in my SQLite database. Is there any other option for saving my array of data, I should consider?

View 3 Replies View Related

General :: How To Edit Default Values Of Memory Min-free Values Of Rom Reside

Apr 9, 2014

I want to ask where does the defaults values of memory min-free values of a Rom reside? I mean what file I would have to edit to edit those values?

View 1 Replies View Related

Android :: Subtracting A Float From Another

Jul 18, 2009

Double mChange = Double.parseDouble("7.1") - Double.parseDouble ("7.15"); Float mChange = Float.parseFloat("7.1") - Float.parseFloat("7.15"); mChange should be -0,05 in both cases, right? So why is mChangeD = -0.05000019 ???

View 5 Replies View Related

Android :: Same Value When Converting From String To Float

Jul 8, 2010

I have a JSON Object with a latitude and longitude String on which I get the values doing this: String latitude = picInfo.getString("latitude"); String longitude = picInfo.getString("longitude");Then I convert them to floats like this: float latInt = Float.valueOf(latitude).floatValue(); float longInt = Float.valueOf(longitude).floatValue();And place them on a GeoPoint like this: GeoPoint X = new GeoPoint((int) (latInt*1E6),(int) (longInt*1E6) ); Debugging this values I can see JAVA approximates the values, is there anyway to keep them exactly the same?

View 6 Replies View Related

Android :: String From EditText To Float

Nov 19, 2010

I have an EditText for which will be using for a float number. So I'm trying to read the text from the EditText and put it into a float variable. But I seem to have a text to float problem.I've tried using Float.parseFloat(string) and just general casting, but nothing seem to do it. What can I do here? Also, is there a way to check for a valid float number before writing it to a variable?

View 1 Replies View Related

Motorola Droid :: Cloud Effect That Float By On Screen?

Aug 23, 2010

what are these clouds that float by on my screen every time I turn on the Droid? Did I miss something somewhere, is it a android thing or my weather program? How can I turn it off?

View 11 Replies View Related

Android :: Avoiding Float Operations In Game Design

Jun 8, 2010

I've read this in a few articles, that one should avoid floating point operations within the physics update of a game.

But how do you really achieve this? Surely all half decent games are going to involve this kind of maths?

Does it mean, convert all your variables to int, or use double instead, or simply just cut it out as much as possible?

View 9 Replies View Related

Android :: SeekBar Minimum And Continuous Float Value Attributes

Jun 9, 2010

I'm looking for a way to implement a minimum value in my SeekBar and also have the option to increment decimal numbers. For example, currently my SeekBar's minimum is set to 0, but I need it to start at the value 0.2. Also, I would like to have the functionality to be able to have the user select a number from 0.2 to 10.0 at a .1 precision so they can choose the numbers 5.6 or 7.1.

Here are the style attributes for my SeekBar:

CODE:..............

View 1 Replies View Related

Android :: Get User Input And Turning It Into Int , Double / Float?

Jun 19, 2010

Does anyone know how to get user input for floats,doubles,ints. I have tried looking everywhere on here and there hasn't been anything that could help me. All it has is EditText.GetText().toString() very frustrated that there isn't a tutorial for this.

View 2 Replies View Related

Android :: Storing Float Numbers As Strings In Database

Apr 27, 2010

So I have an app where I put arbitrary strings in a database and later extract them like this:

CODE:......................

This works fine in all cases except for when the string looks like a float number, for example "221.123123123". After saving it to the database I can extract the database to my computer and look inside it with a DB-viewer, and the saved number is correct. However, when using cursor.getString() the string "221.123" is returned. I cant for the life of me understand how I can prevent this. I guess I could do a cursor.getDouble() on every single string to see if this gives a better result, but that feels sooo ugly and inefficient.

I just made a small test program. This program prints "result: 123.123", when I would like it to print "result: 123.123123123"

CODE:.................

View 1 Replies View Related

Android :: Read A Float Value Form Resources And Accessed From Code?

Dec 3, 2009

Reading values like integers, strings, colors, etc. from resources (xml files) is easy and well defined at http://developer.android.com/guide/topics/resources/available-resourc.... But what about a float value, like 0.1 or 1.4? How can such float value be defined in resource file and accessed from code? Is it possible at all?

View 3 Replies View Related

Android :: One Line Causing Lots Of Garbage Collection.String.format With Float?

Apr 13, 2009

In my ListView, there's one line of code in my ViewBinder that causes lots of garbage collection as I scroll through the list, about every two seconds...

D/dalvikvm(16312): GC freed 13171 objects / 659576 bytes in 162ms D/dalvikvm(16312): GC freed 13122 objects / 654128 bytes in 129ms D/dalvikvm(16312): GC freed 13134 objects / 655416 bytes in 142ms D/dalvikvm(16312): GC freed 13129 objects / 654840 bytes in 129ms D/dalvikvm(16312): GC freed 13149 objects / 655000 bytes in 110ms D/dalvikvm(16312): GC freed 13150 objects / 655720 bytes in 127ms D/dalvikvm(16312): GC freed 13075 objects / 652256 bytes in 111ms D/dalvikvm(16312): GC freed 13232 objects / 659040 bytes in 136ms D/dalvikvm(16312): GC freed 13106 objects / 653920 bytes in 110ms D/dalvikvm(16312): GC freed 13155 objects / 655152 bytes in 110ms

The offending code is here, which formats a price for each item in the list: String price = cursor.getString(columnIndex); final float pricef = Float.parseFloat(price); price = new StringBuffer("$").append(String.format("%. 2f",pricef)).toString(); ((TextView)view).setText(price);

If I comment out the line with String.format, the garbage collection goes away. So what's the "right" way to do this to avoid allocations? That database field holds an unformatted text string which I'm trying to format into proper currency format (example: format "1.5" to "$1.50")

View 9 Replies View Related

Android :: Using Bundle In On Pause

Jan 13, 2010

Is it possible to use bundle and save the data in OnPause() lifecycle method? The scenario is i have 2 edit text and have entered some data i want to retain the data when the activity is killed and started again. his can be achieved using onSaveInstanceState() but as documentation says, this method is not a lifecycle method and hence the callback is not guaranteed. So i wanted to know if there is a way to save it using Bundle in onPause().

View 5 Replies View Related

Android :: How To Persist A Bundle?

Jul 27, 2009

I'm well aware of onSaveInstanceState(Bundle b) and the corresponding onCreate and onRestore. What I want to do is persist the bundle somewhere simple where I'll only ever have one at a time. The functionality is to be able to resume a game from its previously stored state - not to be confused with restoring the activity during its lifecycle. I want to restore it AFTER it's been destroyed (think of turning the phone on and having a button on the game that says, "resume last game". My thoughts are that if I can just persist the bundle that I normally use for the instance state, then I should be able to reload it later upon user request. I don't want to use a provider because they seem way too over the top for what I'm doing.

View 4 Replies View Related

Android :: Way To Serialize A Bundle?

Apr 8, 2010

I'd like to serialize a Bundle object, but can't seem to find a simple way of doing it. Using Parcel doesn't seem like an option, since I want to store the serialized data to file. Any ideas on ways to do this? The reason I want this is to save and restore the state of my activity, also when it's killed by the user. I already create a Bundle with the state I want to save in onSaveInstanceState. But android only keeps this Bundle when the activity is killed by the SYSTEM. When the user kills the activity, I need to store it myself. Hence I'd like to serialize and store it to file. Of course, if you have any other way of accomplishing the same thing, I'd be thankful for that too.

View 2 Replies View Related

Android :: Why Isn't Bundle Getting Passed?

May 11, 2010

I'm trying to pass a bundle of two values from a started class to my landnav app, but according to the debug nothing is getting passed, does anyone have any ideas why?

View 1 Replies View Related

Android :: Bundle Maximum Size

Apr 22, 2009

I am implementing notification handler which logs any changes in content provider and it notifies Broadcast Receiver using custom Intent on periodic basis.But problem here is from Provider to Receiver all the values passed through Bundle.

View 2 Replies View Related

Android :: How To Send Objects Through Bundle?

Nov 22, 2010

I need to pass a reference to the class that does the majority of my processing through a bundle. The problem is it has nothing to do with intents or contexts and has a large amount of non-primitive objects. How do I package the class into a parcelable/serializable and pass it to a startActivityForResult?

View 4 Replies View Related

Android :: Way To Pass Bundle On StartActivity?

Apr 20, 2009

What's the correct way to pass a bundle to the activity that is being launched from the current one? Shared properties?

View 2 Replies View Related

Android :: How To Save Array In Bundle?

Sep 18, 2010

I have 2 dimensions array like this: public myArrayType[][] mObjArray; I want to save it in the onSaveInstanceState method, since my array contains lot of elements I don't want to save element by element but the whole array object, what is the best way?

View 4 Replies View Related

First Android App And Null Bundle Object

Oct 29, 2012

I've gone through the Notepad Tutorials and they are all working on my virtual device. I am now stuck in the midst of trying to write my own Android app.

My setup:
Windows 7 SP 1 64-bit
Eclipse Indigo Service Release 2
Android Development Tools 16.0.1.v201112150204-238534
Android Virtual Device Platform 2.3.3, API Level 10, CPU/ABI ARM (armeabi)

The app is about as simple as they come - you enter a number, it divides it by another number and displays the result.Here is the code involved:

AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.driving"
android:versionCode="1"
android:versionName="1.0" >
[code]...

By the time DrivingTimeEstimator's onCreate() method gets executed, the Bundle object (savedInstanceState) is null (which I'm guessing is what leads to mMiles being null, which throws a NullPointerException and kills everything).

View 3 Replies View Related

Android :: Way To Test OnCreate With Saved Bundle?

Jun 10, 2010

My app launches the camera to allow the user to capture a picture. Sometimes this causes the OS will kill my App to free up memory for the camera. Once the picture is taken, my app starts back up where it left off using the Bundle I saved in onSaveInstanceState(). My app had a bug where in the code that restores the state. Is there anyway that I can simulate or test this case to make sure I am restoring correctly now? It seems I am having trouble making this happen when I want to test it.

View 4 Replies View Related

Android :: Way To Pass Bundle To Activity Set As Singletask?

Apr 22, 2010

So I have a MapActivity that runs an asynchtask that occasionally updates what exactly it's displaying on the map (via a string). I originally pass this string in from the intent when the activity is first created. And then if you click on one of the drawables on the map, it opens a new activity, which can then create a new mapview (same class) with a different string setting. The problem I have is that I only want one instance of the mapview to be running at once. Thus I set android:launchmode="singletask" in the manifest. This works in that it brings the mapactivity to the front, but is there any way to send it a new intent bundle to get a new setting for the string it needs? I tried regetting the extras from the bundle, but it seems to retain the old bundle, not the new intent that was passed to it. I'm not sure I want to do startActivityForResult because the 2nd activity may or may not want to update the original activity. I hope that made sense. I can post code if necessary, but I think that should explain my situation.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved