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 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.
Any ideas?
OnCreate is only called once.
OnCreate will only be called one time for each lifetime of the Activity.
When onCreate function is called in Android? If one doesn't exist, Android creates one. When Android starts an activity, it calls its onCreate() method. onCreate() is always run whenever an activity gets created.
onCreate() - called before the first components of the application starts. onLowMemory() - called when the Android system requests that the application cleans up memory.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With