从FileObserver吐司 [英] Toast from FileObserver
问题描述
我有一个问题。我使用的是 FileObserver
,它从观看目录到另一个,前者指定目录移到新文件。在我的想法有应显示,说文件的xy已被移动,只要观察者观看目录,也如果应用仅在背景举杯消息。但我没有得到它的工作。
它总是告诉我,有一个的RuntimeException
,而且它不能被不调用完成活套。prepare()
。
I have a problem. I'm using a FileObserver
, which moves new files from the watched directories to another, former specified directory. In my thoughts there should be shown a toast message that says 'File xy has been moved', as long as the observer watches the directory, also if the applications is only in the background. But I didn't get it working.
It always tells me, that there is a RuntimeException
, and that it cannot been done without calling Looper.prepare()
.
13 05-11:21:28.484:
WARN / System.err的(3397):
了java.lang.RuntimeException:不能
创建里面有螺纹的处理程序
不叫活套。prepare()
05-11 13:21:28.484: WARN/System.err(3397): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
我试着用用也处理的方式,但我还没有得到它的工作。
I tried the way with using an handler too, but I also didn't get it to work.
有别人的想法?
先谢谢了。
Has someone else an idea? Thanks in advance.
最好的问候,托比
推荐答案
显然,你FileObserver运行(或)其他线程。您无法修改非UI线程的用户界面。通过一个处理程序到你的FileObserver并从它发送消息。阅读关于处理程序。
Obviously, your FileObserver runs(or is) another thread. You can not modify the UI from non-UI thread. Pass a Handler to your FileObserver and send messages from it. Read about Handlers.
这篇关于从FileObserver吐司的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!