Skip to content Skip to sidebar Skip to footer

Toasts In Andengine Scenes

I am using a scene manage and I have different classes extended from scene which are used to to display different modes. I am getting the prob in Toasting messages. In my Mode1 cla

Solution 1:

The key is to run it on the UI Thread - this is what I use

publicvoidgameToast(final String msg) {
    this.runOnUiThread(newRunnable() {
        @Overridepublicvoidrun() {
           Toast.makeText(MyMainActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    });
}

Solution 2:

in your class extending from BaseGameActivity just make a method like

publicstaticvoidMakeToast(String Msg)
{
    message = Msg;
    Handles.sendEmptyMessage(0);
}

staticHandlerHandles=newHandler()
{
    publicvoidhandleMessage(android.os.Message msg) {

        if(msg.what==0)
        {
            Toast.makeText(myCxt, message, Toast.LENGTH_SHORT).show();
        }
    };
};

and in your scene class you will call. YourBaseGameActivity.MakeToast("Hello World");

message is a static String variable too.

Solution 3:

You can create toast message using following way also.

mainActivity.toastOnUiThread("No moves available for REDO",
                Toast.LENGTH_SHORT);

Post a Comment for "Toasts In Andengine Scenes"