Android service onCreate is called multiple times without calling onDestroy

ぐ巨炮叔叔 提交于 2019-11-27 13:18:38

I had the same problem when my service used the same process with activities(default). but no more problems when I made my service 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"/>

see http://developer.android.com/guide/topics/manifest/service-element.html for information.

I had exactly the same problem when I was dealing with a bluetooth service (the problem occurred during the development). When I disconnected my device and killed the ADB it didn't happen again and onCreate was called only once. I assume it is some bug because it happens from time to time. But maybe you have a slightly different problem...

This might become useful to someone. I had this same issue when storing a map through a bundle in a onSaveInstanceState method in one of my activities. I believe because the map contained references to objects that were being used in other parts of the app (one of them was my service) every time I left said activity, my service would start all over again.

I'm guessing this is android OS shenanigans.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!