If you look at this tutorial I created at
http://androidworkz.com/2010/07/06/source-code-imageview-flipper-sd-card-scanner/
there is an example of one way to save an array object to a file and
to read it back in. I tried using SharedPreferences, etc as described
in the docs and gave up because I couldn't get it to work and this
solution I came up with works perfectly. This is essentially the basis
of the method. It is simple to use... there are 2 functions.

public void saveArray(String filename, String[] output_field) {
 try {
        FileOutputStream fos = new FileOutputStream(filename);
        GZIPOutputStream gzos = new GZIPOutputStream(fos);
        ObjectOutputStream out = new ObjectOutputStream(gzos);
        out.writeObject(output_field);
        out.flush();
        out.close();
 }
 catch (IOException e) {
         e.getStackTrace();
 }
}

@SuppressWarnings("unchecked")
public String[] loadArray(String filename) {
  try {
        FileInputStream fis = new FileInputStream(filename);
        GZIPInputStream gzis = new GZIPInputStream(fis);
        ObjectInputStream in = new ObjectInputStream(gzis);
        String[] read_field = (String[])in.readObject();
        in.close();
        return read_field;
  }
  catch (Exception e) {
          e.getStackTrace();
  }
  return null;
}

You just call them like this.
Save Array: saveArray("/sdcard/.mydata/data.dat", MyArray);
Load Array: String[] MyArray = loadArray("/sdcard/.mydata/data.dat");


If you want to use a different type such as a List<Array> or whatever,
you can just change the functions to use that type. I have found it
works with any object that is Serializeable.

Shawn McAllister


On Jul 16, 12:09 am, 7H3LaughingMan <austin.brk...@gmail.com> wrote:
> I was working on implementing a more advanced list view then the
> standard one they teach you in basic tutorials, and I did find a great
> tutorial explaining how to create your own Adapter and such 
> not.http://www.softwarepassion.com/android-series-custom-listview-items-a...
>
> I do have a working version of the tutorial and I am currently in the
> process of changing the list to suit my needs, but there are a few
> issues I am stumped on. If your run the tutorial code it creates a
> little progress dialog saying that it is retrieving data. In my
> application it is going to be fetching data from the internet and
> storing it in an ArrayList of custom objects. However if I where to
> rotate the screen the progress dialog pops up again, I have no clue on
> how to set it up so that when it rotates that it doesn't recreate
> everything and re-fetch the data and process it again.
>
> Any help is greatly appreciated.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to