编程语言
首页 > 编程语言> > 在Android中更新应用程序时后台服务会发生什么?

在Android中更新应用程序时后台服务会发生什么?

作者:互联网

假设我开始在第一次应用程序启动和启动时声明重复的后台服务.当我提供应用程序更新时会发生什么.该背景服务会被杀死吗?
用户是否必须再次打开应用程序以再次注册后台服务,否则应用程序将在更新时获得一些回调?

编辑-1:作为答案之一,如果应用程序必须重新启动以启动服务,那么警报应用程序如何在更新后正常工作而不重新启动(我相信它使用后台服务来启动警报)?

解决方法:

Will that background service be killed?

它会被杀死.

Will user have to open the app again to register the background service again or app will get some callback on update?

这取决于.基本上它需要用户活动,因为更新后应用程序不会自动重新启动.但是如果您的目标是API 12或更高(您现在应该使用),您可以尝试使用ACTION_MY_PACKAGE_REPLACED广播.根据文件:

Broadcast Action: A new version of your application has been installed over an existing one. This is only sent to the application
that was replaced. It does not contain any additional data; to receive
it, just use an intent filter for this action.

因此,一旦收到此广播,您就可以在BroadcastReceiver中触发某些内容.

标签:android,background-service
来源: https://codeday.me/bug/20190528/1170472.html