Monday, October 24, 2011

Re: [android-developers] Re: Will getFilesDir().getAbsolutePath() ever change?

Is this being saved in persistent storage somewhere?

On Mon, Oct 24, 2011 at 6:12 PM, RLScott <fixthatpiano@yahoo.com> wrote:
OK, here is what I propose doing now.  I would just like to know if it
is robust or advisable:

I have a string named "root" that is initialized by my main activity
as:

root=getFilesDir().getAbsolutePath();

And I have a string called "currentFolder" that holds the current
directory.  It is initially equal to root, but it can change if the
user changes to a subdirectory.

When I want to access a document file I use:

File f = new File(currentFolder, simpleFileName);

To change the current folder I use:

 currentFolder = dirFile.getParent();  //..to navigate up the folder
tree, or
 currentFolder = dirFile.getPath();    //..to navigate down the
folder tree.

where dirFile is a file representing a directory.

Now for the "risky" part:  I propose to save "relativeCurrentFolder"
defined as:

relativeCurrentFolder = currentFolder.substring(root.length());

This works based on the assumption that root should always be a prefix
of currentFolder.  Then when the app initializes, I can reconstruct
currentFolder as:

currentFolder = root + relativeCurrentFolder;

That way, if the platform does change in a way that changes root, then
currentFolder will always be properly reconstituted when the app
starts up again.  Does this seem risky or robust?

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en



--
Dianne Hackborn
Android framework engineer
hackbod@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment