开发者

Toast Notification From FileObserver Class

开发者 https://www.devze.com 2023-03-27 15:50 出处:网络
I have an issue similar to Toast from FileObserver.However, I do not understand how to properly implement the Handler.

I have an issue similar to Toast from FileObserver. However, I do not understand how to properly implement the Handler.

Currently, I have a FileObserver-class and I am passing it context and a handler (context comes from getApplicationContext() from the service I call the FileObserver-class from). The handler I pass in (handle) is defined and created in the service. In the onEvent() of the FileObserver-class, I have:

handle.post(new Runnable() {
    public void run() {
        CharSequence text = "Hello toast!";
        int duration = Toas开发者_开发百科t.LENGTH_SHORT;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }
});

But, I end up with a java.lang.NullPointerException.

How do I properly make the toast notification show up when I send it from the onEvent() of the FileObserver-class?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号