1

I'm developing an Android app, and I need a ThreadPool for background operation (insert/retrieve from database, calculating distances between latent points, etc) in repositories and in a foreground service. The official Android documentation says that it's correct to put ThreadPoolExecutor in a class that extends Application ( https://developer.android.com/guide/background/threading ) but they and other sources also says that's correct write a singleton class holding the ThreadPoolExecutor . I don't need to access context or other android framework related stuff in my ThreadPoolExecutor class, so now I'm confused: should I extend the application or do a singleton class? My doubt is that my foreground service is running even if app is killed, so it may be better use the separate singleton?

Thank in advance!

  • 1
    You may find these helpful: 1. [How to declare global variables in Android?](https://stackoverflow.com/a/708317/3001432) 2. [Singletons vs. Application Context in Android?](https://stackoverflow.com/a/3888560/3001432) 3. [Where does Android community stands with respect to Singletons (Reddit thread)](https://www.reddit.com/r/androiddev/comments/7zf0pp/where_does_android_community_stands_with_respect/) – Alex Krupa Jan 04 '21 at 21:40
  • @AlexKrupa thank you son much for the reply. Just for specify, I don't need and I'm not using any context inside my singleton class who holds my ThreadPoolExecutor implementation – Giovanni Corte Jan 04 '21 at 21:48

0 Answers0