0

I would like to know whether Looper.loop() called multiple times creates multiple loopers??Please find my code below and let me know whether multiple loopers will be created because of this code.If yes then please give me advice to resolve this.

code snippet

Thanks in advance

srinivas
  • 72
  • 1
  • 9
  • here I am starting the thread multiple times because localThread.isAlive() returning false. – srinivas Apr 09 '16 at 08:16
  • no, a Looper is created in `Looper.prepare` method, so there is only one `Looper`, if you start that `Thread` multiple times, you will have multiple `Looper`s but each one is associated with its corresponding `Thread` – pskink Apr 09 '16 at 08:20
  • Thank you pskink.But can you be more specific because i am getting it like" Starting my thread multiple times ==multiple loopers getting created".So i think that i am creating multiple loopers which act like zombies – srinivas Apr 09 '16 at 08:31
  • what do you want to achieve actually? are you aware of `android.os.HandlerThread` class? what is your goal? – pskink Apr 09 '16 at 08:33
  • I need to send mails when there is call so when one call comes i am receiving it through broadcast receiver and starting a async task via looper thread.Now whenever there is a call i am starting a new thread which results in creating a new looper.I want to stop creating multiple loopers and use the one which is existing.. – srinivas Apr 09 '16 at 08:47
  • what do you need `Looper`s for? – pskink Apr 09 '16 at 08:48
  • If there are continuous calls then i need send mails continuously one after the other.So when looper is executing for one call then the other will wait in the message queue till looper gets completed with the current one – srinivas Apr 09 '16 at 08:58
  • @pskink Am i going wrong in using loopers for this case?? – srinivas Apr 09 '16 at 09:13
  • `Am i going wrong in using loopers for this case??` yes going wrong, use one `HandlerThread` instead – pskink Apr 09 '16 at 09:30

0 Answers0