If one event is generated two times within one second and have only one receiver which writes something in file what would be the best way to handle it??? and a service can be started two times? like there is a running service can we start it again, two instances at the same time??
Asked
Active
Viewed 104 times
1 Answers
0
No you cant create the two instance of the same service with same class name.
If service is running it will just restarted.
Look at the explanation given here

Community
- 1
- 1

Vivek Bajpai
- 1,617
- 1
- 19
- 35
-
ok thanx and what about the broadcast receiver? how can we manage that – Ateeq Jul 27 '13 at 18:06
-
broadcast receiver will try to invoke the service when it gets the service running it wont start it and if the service is not running it will the start the service.Again if you really need two service at a time try Intent service http://developer.android.com/reference/android/app/IntentService.html it can used as worker thread and will do what you want to acheive – Vivek Bajpai Jul 27 '13 at 18:45
-
what if the receiver executing the code which is in onreceive() function and another event is launched for the same broadcast receiver which is still executing – Ateeq Jul 28 '13 at 09:08
-
1first of all android system has built in functionality about atomicity of code execution and i suggested you to use Intent service not normal service intent service has worker thread each time your code will execute in separate thread lets say a code is not finished and another request arrive on that case a new thread of same service is launched and it will start executing Also you have to maintain your data atomicity by own .(if its unclear pls do add some sample code ) – Vivek Bajpai Jul 28 '13 at 20:22