Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Only one Looper may be created per thread

Tags:

android

looper

I am having a problem with Android looper. I have a class that has extended AsynTask. Inside doInBackground() method i have Looper.prepare() and some code below.

It runs well and good for the first time but after that it gives an exception " Only one Looper may be created per thread" .

There seems some solution to use Looper.quit() but i am unable to implement it.

Any help will be appreciated.

like image 225
viv Avatar asked Oct 08 '10 06:10

viv


1 Answers

class LooperThread extends Thread {
      public Handler mHandler;

      public void run() {
          Looper.prepare();

          mHandler = new Handler() {
              public void handleMessage(Message msg) {
                  // process incoming messages here
              }
          };

          Looper.loop();
      }
  }
like image 184
qjbagu Avatar answered Sep 27 '22 17:09

qjbagu