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.