Help erasing persistent data

Discussion in 'Developers Corner' started by koopa_troopas, Jun 8, 2011.

  1. koopa_troopas

    koopa_troopas New Member

    10
    0
    May 18, 2011

    Advertisements

    Hi! I have my application almost ready, but I still have a few doubts.

    I'm using the getBApp().getContext().setPersistentData() and getBApp().getContext().getPersistentData() methods in order to store a list of preferences ( I store a list of the user's favourite sites ).

    The problem is that I can't find a way to erase the information stored in a certain position of that list. Does anybody know how I could do it?

    And aslo , is this a correct and efficient way of storing the info, or i should use other ways??

    thanks folks!
     
  2. davidblackledge

    davidblackledge Registered l√úser

    563
    36
    Sep 9, 2008
    NM
    What that does depends on the host implementation.
    Here's the relevant portion of the sample Java Host's implementation which you're probably using:
    Code:
        synchronized void saveSessionState(String compKey)
        {
            if (state != null) {
                File file = getSessionFile(compKey);
    //            System.out.println("*** file for persistent state: " + file.getName());
                File dir = file.getParentFile();
                if (!dir.exists()) {
                    dir.mkdirs();
                }
                try {
                    FileOutputStream out = new FileOutputStream(file);
                    try {
                        state.store(out, base.toString());
                    } finally {
                        out.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    
        File getSessionFile(String compKey)
        {
            String tivo = Misc.isWindows() ? "Application Data/TiVo" : ".tivo";
            return new File(System.getProperty("user.home") + "/" + tivo + "/"+ compKey + ".txt");
        }
    
    "state" is a Properties object which uses compound keys that include the application and tivo ids.
    And storing just includes calling state.setProperty(key, value).
    So, you can't completely get rid of your data. The best you can do is store an empty string for the key. Since it's a Properties object which is a Hashtable, you can't even store null as the value.

    That said, this is all just the host implementation. Your software is running as a piece of the host. That means you can just do your own filesystem storage implementation and have complete control. The setPersistentData is just a convenient thing for quick and easy storage of small bits of info per-connected-TiVo.
     

Share This Page

spam firewall

Advertisements