开发者

Toast Notification From FileObserver Class

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜