Is there a potential issue using a Singleton Java class by both a Service and Activity in an Android application?
Example: Singleton is Singleton Activity is A Service S
Service S has a handle to Singleton. S requests Singleton to launch Activity. Activity calls operational methods defined in Singleton.
I have several Singletons in my application which encapsulate various operations for a functional area. So Activities will interact with various Singletons to perform various operations.
I don't think there is an issue with this approach. I use singletons quite often and never had any problems. You just need to keep in mind that android might remove the singleton instance when it needs the memory, so you need to check for null every time you get the singleton instance.
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