'Delay between bindService() and onBind() when starting a Service
I'm facing a strange problem with my app. I have a LocationService that runs in the background. The way I manage its lifecycle is:
- In
onResume, every activity usesbindService(intent,serviceConnection, BIND_AUTO_CREATE)like that the service is automatically created when needed. - In
onStop, every activity usesunbindService(serviceConnection) - This works because when switching activities, the new
ActivityonResumeis called before the oldActivityonStopmethod
The problem I have is, lets say I start from the home screen and I launch the app with an Activity that has a fragment in it. The order of the function call is as follows
- Activity
onCreate-->setContentViewis called here - Activity
onResume--> herebindServiceis called and should create theService - Fragment
onResume - Service
onBindmethod is called
My question is why is there a something else between my bindServiceand onBind calls?? I have a feeling this has something to do with threading issues.
Solution 1:[1]
In my case, my issue was using android:process attribute for <service> element within Android Manifest, which is supposed to improve performance, but in reallity, maybe it does once the service is running, but it takes a very long while to reach onCreate() (and so also to reach onBind()). For me it was taking minutes. Now Apps and services run smooth and as expected.
More info: https://developer.android.com/guide/topics/manifest/service-element
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
