android service 相关知识.docVIP

  • 3
  • 0
  • 约1.32万字
  • 约 18页
  • 2017-12-12 发布于河南
  • 举报
android service 相关知识

android service 学习(上) ? Service是android?系统中的一种组件,它跟Activity的级别差不多,但是他不能自己运行,只能后台运行,并且可以和其他组件进行交互。Service的启动有两种方式:context.startService() 和 context.bindService()。 ? 使用context.startService() 启动Service是会会经历: context.startService() ?-onCreate()- onStart()-Service running context.stopService() | -onDestroy() -Service stop? ? 如果Service还没有运行,则android先调用onCreate()然后调用onStart();如果Service已经运行,则只调用onStart(),所以一个Service的onStart方法可能会重复调用多次。? ? stopService的时候直接onDestroy,如果是调用者自己直接退出而没有调用stopService的话,Service会一直在后台运行。该Service的调用者再启动起来后可以通过stopService关闭Service。 ? 所以调用startService的生命周期为:onCreate -- onStart(可多次调

文档评论(0)

1亿VIP精品文档

相关文档