Hi,
In my app, I need to do some file writing operations, such as saving
bitmap
to sdcard file:
OutputStream fos = new FileOutputStream(new File("name"));
bitmap.compress(Bitmap.CompressFormat.PNG, 0, fos);
and it is implemented in a separate thread.

I interrupt the thread by calling Thread.interrupt() when unmounting
SD card,
and receives the following log:
E/vold    ( 1132): Killing process 7646
E/vold    ( 1132): process com.android.video (8654) has open file /
sdcard/Android/data/com.android.video/cache/
_sdcard_video_video-2010-05-09-00-47-07.3gp.png

It seems that I didn't close the thumbnail cache file, and it results
in my process being killed.

So my question is how can I stop File write operation before interrupt
the thread?
The android document says that using InterruptibleChannel can cause
ClosedByInterruptException,
so I tried to use:
OutputStream fos = Channels.newOutputStream(new FileOutputStream(new
File(cachePath)).getChannel());
[ see http://forward.com.au/javaProgramming/HowToStopAThread.html ]

but it just didn't work, since no ClosedByInterruptException could be
caught...

So how can I close the open file before umounting SD card ?
I think It's really very common.

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