Problem with restoring data from pause

Last Updated:

  1. Jinam

    Jinam Member This Topic's Starter

    Mar 8, 2010
    Likes Received:
    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
    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) {
    return buf.toString();

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

    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??


Share This Page