安卓:Activity.onDestroy()重新启动服务 [英] Android: Activity.onDestroy() restarts service

查看:620
本文介绍了安卓:Activity.onDestroy()重新启动服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在后台运行,使用服务的应用程序。但是,当的onDestroy被称为主要活动,服务得到reseted,重新调用的onCreate和在onStart。我怎么能prevent呢?

I've got an app that runs in the background, using a service. But when onDestroy is called in the main activity, the service gets reseted, calls onCreate and onStart over again. How can i prevent this?

推荐答案

您不得不看的价值从onStartCommand方法的服务回报。默认值是START_STICKY被破坏之后,将重新启动该服务。看看在<一个href=\"http://developer.android.com/reference/android/app/Service.html#onStartCommand%28android.content.Intent,%20int,%20int%29\"相对=nofollow> onStartCommand文档了解更多详情:

you have to look at the value the service returns from its onStartCommand method. The default value is START_STICKY which will restart the service after it is destroyed. Take a look at the onStartCommand documentation for more details:

这篇关于安卓:Activity.onDestroy()重新启动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆