Android的服务的onCreate被多次调用,而不调用的onDestroy [英] Android service onCreate is called multiple times without calling onDestroy

查看:2573
本文介绍了Android的服务的onCreate被多次调用,而不调用的onDestroy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我使用的是服务,我们的服务器进行通信。该服务会生成多个消息队列的线程来处理具有不同优先级的任务。

In my app, I use a service to communicate with our server. The Service spawns several message queue threads to deal with tasks with different priorities.

该模型已被用于一年左右没有大的问题。然而,最近,我发现有些时候我的服务类的的onCreate 被多次调用。 的onDestroy 是从来没有两个的onCreate 调用之间调用。所以,我没有得到机会杀死现有的线程。一旦这种行为发生时,该服务有重复的线程里面。

This model has been used for about one year without big issues. However, recently, I found some time the onCreate of my service class are called multiple times. onDestroy is never called between two onCreate calls. Therefore, I did not get chance to kill existing threads. Once this behavior happens, the service has duplicate threads inside.

我唯一改变的是运行作为前台服务是在应用程序中的用户登录该服务。我想知道前台服务是否会导致问题。

The only thing I have changed is to run the service as foreground service is a user signs in the app. I am wondering whether foreground service cause the problem.

任何想法?

推荐答案

我有同样的问题时,我的服务中使用的相同的过程,活动(默认)。但没有更多的问题,当我做了我的服务使用另一个进程。我编辑我的Andr​​oidManifest.xml中像下面...(添加机器人:进程属性)

I had the same problem when my service used the same process with activities(default). but no more problems when I made my service to use another process. I edited my AndroidManifest.xml like below... (added android:process attribute)

<service android:name="kr.co.pkbio.binoo.CacheFileManagerService" android:process=":kr.co.pkbio.binoo.service"/>
<service android:name="kr.co.pkbio.binoo.ActivityStackManagerService" android:process=":kr.co.pkbio.binoo.service"/>

看<一href="http://developer.android.com/guide/topics/manifest/service-element.html">http://developer.android.com/guide/topics/manifest/service-element.html了解相关信息。

这篇关于Android的服务的onCreate被多次调用,而不调用的onDestroy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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