0

I am getting the error

02-11 21:40:25.326: E/AndroidRuntime(1950): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

when trying to create a dialog. The class that I need to do this in does not extend activity (I pass context to this class from another class), so I am looking for a way to create a simple popup message in the default android style without this error. Thanks.

user2005938
  • 159
  • 2
  • 2
  • 14

1 Answers1

0

By default only main thread(UI thread) has a looper which you can use to process your events. That means when you create a child thread(non-UI thread) , it will not have a looper. By calling Looper.prepare, you create a new Looper object for your child thread and only then you can get a handler object. But I guess this is not you want (The Looper is used inside Handler and normally you don't care about its usage. ).

An approach is using getMainLooper as the parameter to handler constructor . This way you use the same looper object as that of the UI thread

suitianshi
  • 3,300
  • 1
  • 17
  • 34