0

I have a foreground Service which is used for audio recording (AudioRecordingService). Declared in AndroidManifest as such:

<service
     android:name=".recording.AudioRecordingService"
     android:stopWithTask="true" />

It extends Service and is started with startService

public class AudioRecordingService extends Service

Intents are received in onStartCommand.

In onDestroy I stop the audio recording and launch another foreground service which handles the audio upload.

onDestroy is not called in AudioRecordingService when the app is closed by swiping the app away (closing the task). It is only called when stopSelf is called on the service.

Nipun Thennakoon
  • 3,586
  • 1
  • 18
  • 26
Vlad
  • 988
  • 12
  • 18

2 Answers2

0

I think you need to set your activity to be a task.

https://developer.android.com/guide/components/activities/tasks-and-back-stack

see: "singleTask"

mrmichaeldev
  • 329
  • 3
  • 11
  • I am using a `Service`, not an `Activity`. "singleTask" is the Activity's launchMode. It describes how the activity is started. – Vlad Jul 09 '18 at 15:21
  • I understand, I believe for stopwithtask to work that your activity needs to be a task. https://developer.xamarin.com/api/field/Android.Resource+Attribute.StopWithTask/ – mrmichaeldev Jul 09 '18 at 17:23
0

Seems like it's not guaranteed that onDestroy will be called. More information can be found in this post: Is an android service guaranteed to call onDestroy()?

Vlad
  • 988
  • 12
  • 18