android - calling ui thread from worker thread

后端 未结 7 2233
再見小時候
再見小時候 2020-12-11 00:12

Hi I want to make Toast available to me no-matter-what and available from any thread whenever I like within my application. So to do this I extended the A

7条回答
  •  情深已故
    2020-12-11 01:14

    This will allow you to display the message without needing to rely on the context to launch the toast, only to reference when displaying the message itself.

    runOnUiThread was not working from an OpenGL View thread and this was the solution. Hope it helps.

    private Handler handler = new Handler();
    handler.post(new Runnable() {
        public void run() {
            Toast.makeText(activity, "Hello, world!", Toast.LENGTH_SHORT).show();
        }
    });
    

提交回复
热议问题