Monday, October 24, 2011

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

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

No comments:

Post a Comment