So i’m trying to implement In-App-Billing and the problem is that I need my BillingHelper/ReponseHandler to run on the UI thread. When i create the handler in my Screen class which only inherits the Activity as an argument. And runs on the Open GL Thread I get the error below.
10-16 18:36:28.500: E/AndroidRuntime(28263): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Please help.
The handler needs to be constructed on the thread where you want your posted runnables to execute. So if you want to run something on the UI thread, you have to construct the handler on the UI thread and pass it to the worker thread somehow (typically during thread object construction, either explicitly or via closure).
There’s a shortcut though. The method
Activity.runOnUiThread()takes aRunnableand executes in on the UI thread, no handler necessary.