First of all i'd like to say two things. The first being, sorry if this question has already been asked, i've searched for similar questions around this topic but was unable to find a solution. Secondly sorry for the lengthy question, and please let me know of any error and I will be sure to make appropriate changes :).
I am relatively new to Android development (approx 2 months), so please forgive my ignorance. The question I have is regarding the android service.
My issue is as follows, I have created the following 3 applications:
- An android library which contains a small test service (myService).
- An application (TestApplicationOne) which has access to the android library.
- Another application (TestApplicationTwo) which also has access to the android library.
My current solution works as follows, TestApplicationOne references the custom library and uses this library to connect to the service (myService) via the bindService() method. Upon connection successful the application then adds itself to a collection of observers located within myService. Each object in this collection is notified each time the service needs to broadcast a message.
When ran, the above solution seemed to work fine. However, I now have another application (TestApplicationTwo) which would also like to use the same service as the one above. The implementation of TestApplicationTwo was created to the same workings/spec of the first application (TestApplicationOne).
The issue I have is that when the service is started in either application, the other application is not notified of any events.
I have tried to implement several approaches to solve this. Such as using the Singleton pattern to retain a single instance, but the problem still seems to exist. My only comprehension of this is that each time either application is started, a new instance of the library is created. Thus the library referenced in TestApplicationOne is not the same instance as the library referenced in TestApplicationTwo, and as a result, not being notified.
Is there anybody with any experience in this issue? Or can think of any possible solution?
Thank you in advance of any help, it is much appreciated.
John