2

Sorry but, I'm quite a bit confused after reading this. If let say, I have a single Activity and inside it, I tried to make an inner Class implementing Thread that has looper and handler.

My question is; If I finish() my activity. Is that close any Looper / Handler i just created last time?

I'm afraid the Thread is still running background altough the Activity is already closed -> ended.

Community
  • 1
  • 1
gumuruh
  • 2,544
  • 4
  • 33
  • 56

1 Answers1

3

After finish, you don't have to care about Handlers attached to the Main Thread, because it's Looper (and the Thread itself) is managed by the system, and it will quit when it is necessary.

However if the Handler is attached to a separate Looper that is not managed by the system (for example a Thread with a Looper started by you), it will be there in case you have not stopped the relevant Thread (that has the Looper). This true in general for all Threads, the fact that the Thread has a Looper does not change the situation.

So the important think here is to stop every Thread that you started manually.

As an addition:

  • You can always check your running Threads in Eclipse. Just attach the debugger and go to the Debug view. All Threads will be listed there.
  • Take a look at HandlerThread.
kupsef
  • 3,357
  • 1
  • 21
  • 31
  • 1
    "After the finish() call, all Handlers attached to the "Main UI Thread" will be stopped (because the main Thread's Lopper quit)." this is **obviously** not true, why would finish() force Looper.quit()? – pskink Jul 12 '14 at 09:04