Android Forums

Go Back   These FORUMS ARE DISABLED!! OUR NEW FORUMS ARE AT http://androidforum.com/ > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
 
 
LinkBack Thread Tools Display Modes
Old 03-29-2010, 09:21 AM   #1
Junior Member
 
Join Date: Mar 2010
Posts: 2
Friends: 0
View jinam's Profile   View jinam's Photo Album   View jinam's Blog   View Social Groups
I use an array named puzzle of 121 items(11x11) as a map for my Tower Defence, i have 0 for road, 1 for hill, 2 for base and 3,4,5,6,7,8,9 for towers.
The problem is that when i want to save/restore on onPasue/onResume i have to transform this array into a string because the
"getPreferences(MODE_PRIVATE).edit().putString(PRE F_PUZZLE,
toPuzzleString(puzzle)).commit();"
has no putArray so i decided to transform my array into a string with 2 methods 1 from array->string and 1 from string->array listed bellow



static private String toPuzzleString(int[] puz) {
StringBuilder buf = new StringBuilder();
for (int element : puz) {
buf.append(element);
}
return buf.toString();
}



static protected int[] fromPuzzleString(String string) {
int[] puz = new int[string.length()];
for (int i = 0; i < puz.length; i++) {
puz[i] = string.charAt(i);
}
return puz;
}
I get my string with :
puz = getPreferences(MODE_PRIVATE).getString(PREF_PUZZLE ,
easyTD);

and get my array back(finnaly) with

fromPuzzleString(puz);

In "theory" this should work...but when i click the continue button the array is compeltly modified not only in value but in its lenght too.
Any ideah on where did i go wrong??? or any diffrent ideah on how should i save/restore that array??
jinam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
 

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Data sync? koffi Android Chat 2 10-19-2010 08:58 PM
Data card ezeddie Droid 1 03-13-2010 01:52 PM
Data Plan jayaskren T-Mobile, Vodafone, Sprint, Verizon, Rogers, AT&T etc. 3 10-25-2009 06:46 PM
Data Usage pcb007 Android Games And Applications 0 10-25-2009 03:39 AM
Hidden Data... mcc25 Android Hardware 2 12-24-2008 11:20 PM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 05:05 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2012 TalkAndroid.com. All rights reserved.