应用程序无响应(ANR)执行服务机器人 [英] Application Not Responding (ANR) executing service android
问题描述
host.activity是我的包和host.framework.ServicePromemoria是一个Android的服务。
host.activity is my package and host.framework.ServicePromemoria is an android service.
这是什么意思的错误??
What does this error mean??
我可以捕获该异常,并避免错误?
Can I catch the exception and avoid error?
推荐答案
这意味着你的服务做一个相当长的操作(大部分是ANR的运营大于5秒),这样做是在UI线程上。这可能是一个网络的任务,或一个数据库的任务,或一些其它长时间操作。
This means that your service is doing a rather long operation (most ANRs are from operations greater than 5 seconds) and is doing it on the UI thread. This could be a network task, or a database task, or some other long operation.
您可以通过运行任务在服务关闭主UI线程,使用的发或 AsyncTask的。
You can fix this by running the task in a service off the main UI thread, by using a Thread or an AsyncTask.
逸岸,就可以直接启动您的服务进入一个新的线程,如下:
Infact, you can directly start your service into a new thread as follows:
Thread t = new Thread(){
public void run(){
getApplicationContext().bindService(
new Intent(getApplicationContext(), YourService.class),
serviceConnection,
Context.BIND_AUTO_CREATE
);
}
};
t.start();
此外,通过高速缓存返回bindservice的价值,如果有的话,如果你需要它供以后使用。
Also, cache the value returned by bindservice, if any, if you require it for later use.
这篇关于应用程序无响应(ANR)执行服务机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!