onDestroy 在使用 stopWithTask= 时未在服务上调用 = "true"



我有一个前台Service,用于音频录制(AudioRecordingService(。在AndroidManifest中声明为:

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

它扩展了Service,并以startService启动

public class AudioRecordingService extends Service

意愿在onStartCommand中被接收。

onDestroy中,我停止音频录制并启动另一个前台服务来处理音频上传。

当通过滑动应用程序关闭应用程序(关闭任务(时,onDestroy不会在AudioRecordingService中调用。只有在服务上调用stopSelf时才会调用它。

我认为您需要将活动设置为任务。

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

请参阅:"singleTask">

似乎不能保证会调用onDestroy。更多信息可以在这篇文章中找到:android服务是否保证会调用onDestroy((?

最新更新