1

I am using ExecutorService executor = Executors.newFixedThreadPool(1); in Main activity for networking stuff.

My question is, for other class or activity i have to use this executor object or i have to do shutdown this Executor at end of my main activity and create new instance in other class or activity? What is the bast practice?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Cyrus the Great
  • 5,145
  • 5
  • 68
  • 149

1 Answers1

1

A fixed thread pool executor maintains a thread.

If you want to run code on the same thread you should use the same executor, if you want to run code on a different thread you should create a new executor.

It does not matter that much if an executor is shared between activities or not, you only need to take care of shutting it down eventually.

TpoM6oH
  • 8,385
  • 3
  • 40
  • 72