"Process safe" would be the issue. Within a process, activities all
run on the same thread, so there's not much concurrency issue there.

I hope you have a very good reason to split your application across
processes. I can think of a few, but they all cause headaches...

Renaming a file is atomic. You can use this to ensure that a file
cannot be read before it is complete and ready.

For coordination, you can either accept the risk that two processes
may be caching the same file at the same time and wasting some effort,
or you can use a service to coordinate, or you can use the filesystem.
You can write a file into a directory that's both process-specific and
specific to the file in question, and attempt to rename the directory
to one that's not process-specific. Since you can't rename a directory
to replace a non-empty directory, this will fail if another process
got there first. If th rename succeeds, you can then write your cache
file into this directory, and when done, rename it out into the final
cache location, and delete your temporary directory.

There's not much documentation on it, but it looks like
android.os.FileWatcher could be used to wait for a cached file to be
available without polling.

But I think a single cache manager is simpler, where you ask the cache
manager for the file, and it notifies you when it's ready. This can be
a service. Or it can be even lower overhead if you stop splitting your
app between processes.

There's also android.os.MemoryFile, but I'm not sure of the
performance implications and caveats of using it.

On Mar 16, 8:40 pm, magicpig <zsumagic...@gmail.com> wrote:
> Hi,
>
>       I would like to share a cache file across activities, which are
> running in different processes but in a same application.
>
>       The operations on the file are:
>       Read: context.openFileInput->read fileInputStream->close
> fileInputStream
>       Delete: context.deleteFile
>       Write:context.openFileOuput->Write to fileOutputStream  ->close
> fileOutputStream
>
>       So, is there any way to make it thread safe (probably not
> "thread safe", should we call it "activities safe" or "process
> safe" ?:-) )
>
> Thanks a lot.

-- 
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