On Thu, Aug 16, 2012 at 7:57 AM, Mark Murphy <mmur...@commonsware.com>wrote:

> On Thu, Aug 9, 2012 at 11:23 AM, Digipom <digi...@gmail.com> wrote:
> > I got bitten by this the hard way. The official documentation on services
> > doesn't have any warnings about this, so I figured onDestroy() was good
> > enough. I had some audio shut down code in onDestroy() that wasn't
> getting
> > called when the phone was being shut down, so I'd have a corrupt file
> > because the MP4 file would not be properly finished by Android's
> > MediaRecorder.
> >
> > What would you recommend as an ideal way to handle this? Trap the shut
> down
> > intents?
>
> If by that you mean register a BroadcastReceiver from the service for
> ACTION_SHUTDOWN, that's certainly worth a shot.
>

I hooked onto this as well as the HTC equivalent, and it seems to work. I
opened a bug against the documentation for onDestroy(), and it's been filed
for a future release.


>
> > Unfortunately, it seems that won't handle other instances where the
> > app might kill the service, though I do register it as a foreground
> service.
>
> Not everything is designed to be used indefinitely by a service.
>

It's hard to think of something more suited to a service than recording in
the background.

However, with foreground mode + the broadcast receiver for shut down, this
captures most of the cases. At least on newer versions of Android, I
haven't seen it kill the service otherwise. I suppose it's still possible
which is really unfortunate, because MP4 and 3GP files that haven't been
terminated properly are a pain to repair. WAVE on the other hand is no big
deal.

For anyone else reading this, it also seems that Android's media recorder
is not smart enough to terminate the file if it runs out of disk space, so
you'll also need to filestat the file and make sure you're not dangerously
low on free space remaining.


>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> Android Training in NYC: http://marakana.com/training/android/
>
> --
> 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
>



-- 
-- 
Digipom
http://www.digipom.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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to