Service要点

来源:互联网 发布:网络的好处 编辑:程序博客网 时间:2024/05/21 09:42

A services runs in the same process as the application in which it is declared and in the main thread of that application, by default. So, if your service performs intensive or blocking operations while the user interacts with an activity from the same application, the service will slow down activity performance. To avoid impacting application performance, you should start a new thread inside the service.

默认情况下,服务和应用程序运行在同一个进程当中,也是应用程序的主线程。当用户和一个activity进行交互时,如果该activity调用的服务要进行复杂或者有可能造成堵塞的操作,这时就很可能会对activity的运行造成影响,甚至出现ANR现象。要避免这种情况,你应该在服务里面启动一个新线程来完成复杂的操作。

原创粉丝点击