Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 class extended from scene I want to show a toast message but it gives error that "Cant create handler inside thread that has not called looper.prepare()"

I tried to do this inside handler but same result. I tried to make a static handler in main class but no result. Can any one tell me the solution?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
273 views
Welcome To Ask or Share your Answers For Others

1 Answer

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();
        }
    });
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...