我有一个前台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((?