Service

1. Service(服务)与Activiy都间接继承于Context。简单理解为是后台与前台的区别。

    Service也要在AndroidManifest.xml里面声明。

A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.

A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).

 

2.在Service中逻辑添加在onCreate和onStart中,如果做一些很耗时间的事情,最好在Service里启动一个线程来完成,因为Service是跑在主线程中,会影响到UI操作或者阻塞主线程中的其他事情.

 

3.两种启动方式(1).启动执行过程:context.startService(intent)->onCreate()->onStart()->服务运行,其中onCreate可以进行一些服务的初始化工作,onStart()则启动服务。
    停止执行过程下:context.stopService(intent)->onDestroy()->服务停止。
 http://blog.sina.com.cn/s/blog_5e32cc130100gvc7.html).启动执行过程:context.bindService(intent)->onCreate()->onBind()->服务运行(2停止执行过程下:context.unbindService()->onDestroy()->服务停止。

4. If we want to make this service run in a remote process (instead of the standard one for its .apk), we can use android:process in its manifest tag to specify one:

<service android:name=".app.MessengerService"
        android:process=":remote" />

Note that the name "remote" chosen here is arbitrary, and you can use other names if you want additional processes. The ':' prefix appends the name to your package's standard process name.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值