Error when i call asyncService.getLeaderBoard(gameName, max, this); on andriod gameupdate

0 votes

Error when i call  asyncService.getLeaderBoard(gameName, max, this); on andriod gameupdate 

Error message 

Can't create handler inside thread that has not called Looper.prepare()

Please how can i call this method from main thread when my gamestate is game over ?

Is there a way to call mainthread from another thread?

asked Jun 25, 2015 in App42 Cloud API-BaaS by Oti Chibueze (10 points)

1 Answer

0 votes


In Android if you are doing some operation in background Thread,and want to update respective Game UI once data received. In this case you have to move from background thread to UI Thread.

In your case you are updating UI in background Thread so I would like to suggest you to use following code.

activity.runOnUiThread(new Runnable() {
  public void run() {
    //You can write Ui code here

Let me know if it helps.


Vishnu Garg

answered Jun 25, 2015 by Vishnu Garg (674 points)
I have an activity class and view class  here is what the view class looks like where I call update and draw So where do I place this code is it on the general run ()  where the update draw method is or I place the method call inside

        thread = new TimePuzzleThread(holder);

    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub
            editor = settings.edit();
        catch(Exception ex){}      

private SurfaceHolder mSurfaceHolder;
    public class TimePuzzleThread extends Thread{
        public TimePuzzleThread(SurfaceHolder surfaceHolder){
            mSurfaceHolder = surfaceHolder;
        public void run(){
            while (true){
                //breaks the thread here when
                Canvas c = null;
                    c = mSurfaceHolder.lockCanvas(null);

                catch(Exception ex){}
                    if (c != null){mSurfaceHolder.unlockCanvasAndPost(c);}
You can place the in onCreate method of Activity once you got the result you can draw it on a View by using runOnUiThread function that I have shared earlier.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on