WEB开发网
开发学院手机开发Android 开发 Android Service 笔记 阅读

Android Service 笔记

 2010-08-22 04:47:00 来源:WEB开发网   
核心提示:onUnbind()方法,如果这个Service允许连接,Android Service 笔记(3),onBind()返回客户端和Service交互的通信频道(the communications channel that clients use to interact with the service),如果有新的客
onUnbind()方法。如果这个Service允许连接,onBind()返回客户端和Service交互的通信频道(the communications channel that clients use to interact with the service)。如果有新的客户端链接到Service,onUnbind()方法可以请求调用onRebind()。

3、权限(Permissions)

在manifest 文件中声明的Service可以被全局访问(所有的应用程序都可以访问这个Service)。为了可以访问这个Service,其他的程序需要在他们的 manifest文件中声明相应的< uses-permission> 来使用启动、停止或者绑定到这个Service。

另外,Service可以通过权限(通过在执行那个调用的实现之前调用checkCallingPermission(String))保护自己的IPC调用。

4、进程生命周期(Process LIfecycle)

Android系统会尽量保持使用Service的进程尽可能长(Service被启动或者有客户端绑定到Service)。当系统内存变低,系统需要kill现存的进程时,Service的hosting进程的优先级将会在下列的可能中保持更高。

If the service is currently executing code in its onCreate(), onStart(), or onDestroy() methods, then the hosting process will be a foreground process to ensure this code can execute without being killed.

If the service has been started, then its hosting process is considered to be less important than any processes that are currently visible to the user on-screen, but more important than any process not visible. Because only a few processes are generally visible to the user, this means that the service should not be killed except in extreme low memory conditions.

If there are clients bound to the service, then the service's hosting process is never less important than the most important client. That is, if one of its clients is visible to the user, then the service itself is considered to be visible.

注意:大多数时间你的Service是运行的,但在严重的内存压力下它也可能被系统kill。如果是这样,系统会在稍后尝试重新启动这个Service。 An important consequence of this is that if you implement onStart() to schedule work to be done asynchronously or in another thread, then you may want to write

上一页  1 2 3 4 5 6 7  下一页

Tags:Android Service 笔记

编辑录入:coldstar [复制链接] [打 印]
赞助商链接