Android service onCreate is called multiple times without calling onDestroy

后端 未结 3 1165
说谎
说谎 2020-12-03 00:07

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.

This model

相关标签:
3条回答
  • 2020-12-03 00:24

    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.

    0 讨论(0)
  • 2020-12-03 00:34

    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.

    0 讨论(0)
  • 2020-12-03 00:44

    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...

    0 讨论(0)
提交回复
热议问题