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

    public void gameToast(final String msg) {
    this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
           Toast.makeText(MyMainActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    });
}

Solution 2:

in your class extending from BaseGameActivity just make a method like

public static void MakeToast(String Msg)
{
    message = Msg;
    Handles.sendEmptyMessage(0);
}

static Handler Handles = new Handler()
{
    public void handleMessage(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"