I am experiencing something similar, except on a sporadic basis. For the most part, my application, on receipt of an ACTION_MEDIA_EJECT event, is able to close files and return before the reaper arrives to clean-up. However, sometimes, when the application is writing data to one of the files, the reaper appears and kills the application before it has a chance to finish writing and close the file. This results in data corrupted on the SD card.
Any suggestions for a solution? According to LogCat, it looks like the reaper is unleashed around 1 second after ACTION_MEDIA_EJECT is received. Do I have to ensure that all clean-up happens within that time period? Yikes! On Jul 11, 2:23 am, Streets Of Boston <flyingdutc...@gmail.com> wrote: > Register your broadcast receiver like this: > > IntentFilter intentFilter = new > IntentFilter(Intent.ACTION_MEDIA_EJECT); > intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); > intentFilter.addDataScheme("file"); > intentFilter.addDataAuthority("*", null); > intentFilter.addDataPath((mIsExternal > ?CursorUtils.EXTERNAL_STORAGE_ROOT > :CursorUtils.PHONE_STORAGE_ROOT).getAbsolutePath(), > PatternMatcher.PATTERN_LITERAL); > context.registerReceiver(this, intentFilter); > > Then close all your files when you get an ACTION_MEDIA_EJECT > and re-open them (if necessary) on ACTION_MEDIA_MOUNTED. > (in the 'public void onReceive(Context context, Intent intent)' method > of this broadcast receiver). > > (EXTERNAL_STORAGE_ROOT is the standard value for external-storage > (usually "/sdcard") and PHONE_STORAGE_ROOT is "/emmc" (for HTC > Incredible and such phones)). > > I'm not sure if this is the 'official' way of doing it, but it works > for me. :) > > On Jul 10, 3:50 pm, ls02 <agal...@audible.com> wrote: > > > I register for this broadcast. However theprocessis killed before I > > receive any broadcast event. > > > On Jul 10, 2:59 pm, Dianne Hackborn <hack...@android.com> wrote: > > > > There is a broadcast sent when theSDcardis being unmounted (sorry I don't > > > remember the name off-hand). You should close all your files at that > > > point. > > > If you don't, the platform needs tokilltheprocessbecause Linux can't > > > unmount the file system while any files remain open on it. > > > > On Sat, Jul 10, 2010 at 10:35 AM, ls02 <agal...@audible.com> wrote: > > > > I found that Android kills my appprocessthat has files open onSD > > > >cardwhen thecardis mounted when the device connects to a computer. > > > > It is done without any notification, I see in the log something like > > > > KillProcessWithFilesOpenedOnCard message, my app receives no > > > > notification, has no chance to gracefully shutdown. Moreover Android > > > > restarts my app immediately after killing it with latest Activity not > > > > the default activity launched in default standard mode. It does it > > > > while thecardis still mounted and device is still connected to a > > > > computer. > > > > > Can someone explain this all to me, how it I supposed to work, and if > > > > there is any way to alter this weird rude behavior? Particularly, if > > > > there is way to get any notification before theprocessis killed by > > > > the OS and to prevent relaunching it while thecardis still mounted? > > > > > -- > > > > 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<android-developers%2bunsubscr...@googlegroups.com> > > > > For more options, visit this group at > > > >http://groups.google.com/group/android-developers?hl=en > > > > -- > > > Dianne Hackborn > > > Android framework engineer > > > hack...@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.- Hide quoted text - > > > - Show quoted text - > > -- 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