Re: [android-developers] Replacement for MODE_WORLD_READABLE
On Tue, Jan 1, 2013 at 8:21 PM, William Ferguson
<william.ferguson@xandar.com.au> wrote:
> Thanks Mark that's perfect. I'd always shied away from ContentProviders
> because they looked miles too heavy weight and complex but that is a neat
> and simple solution.
>
> One question: Why the does #onCreate copy the target file? Is it just to
> validate that you can read the file? Shouldn't that be done later since
> #onCreate is called on every App startup?
The file is shipped in assets/, and you cannot readily serve an asset
from a ContentProvider. It is tons easier if the file is a regular
file on the filesystem. So, onCreate() sees if the file was already
copied to internal storage, and if not, makes a copy from the asset.
The check for file existence should be pretty fast. Besides, this is a
book demo, and so I routinely cut corners in the interest of reducing
lines of code count to make the samples more focused on the problem at
hand.
In your case, the file already exists on the filesystem, so you can
probably just junk my onCreate() entirely.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy
Här kan du ställa och svara på frågor om applikationsutveckling på
Android: http://www.andglobe.com
--
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
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home