在android中删除应用程序时停止重新启动服务

在android中删除应用程序时停止重新启动服务,android,android-service,Android,Android Service,我正在从我的应用程序上传一些多媒体,并在服务中使用START_粘滞来保持我的应用程序的活力。问题是,当我从最近的任务中删除我的应用程序时,服务会重新启动,导致我的上传被取消 I dont want my service to be restarted when the app is removed from the recent task And keep the uploading going on And then inform back to my app. How to do. 如果

我正在从我的应用程序上传一些多媒体,并在服务中使用START_粘滞来保持我的应用程序的活力。问题是,当我从最近的任务中删除我的应用程序时,服务会重新启动,导致我的上传被取消

I dont want my service to be restarted when the app is removed from the recent task And 
keep the uploading going on And then inform back to my app. How to do.

如果要验证任务是否已删除,请在服务中覆盖onTaskRemoved

@Override
public void onTaskRemoved(Intent rootIntent) {

}

您需要使用前台服务以确保该服务不会被终止

只要您的服务不在前台,并且您的应用程序不是系统应用程序,您就无法确保它将永远运行,直到上传过程完成

“可能”viber或微信或任何使用包含回帖的服务,更可能是“简历”技术的服务。这将重新启动服务,比较已传输的字节数,并在最后一个位置继续


您将看到“外观和感觉”,它仍在运行

我看到了“微信”应用程序。当我上传任何照片或视频并从最近的任务中删除微信时,它不会重新启动其服务,甚至不会使用任何前台服务。我对前台服务一点也不感兴趣,我想我需要在一个单独的“流程”中的服务中开始上传。