美文网首页
Service是单例

Service是单例

作者: HWilliamgo | 来源:发表于2018-08-09 14:32 被阅读7次

    stackoverflow上的3个问题解答了我的疑惑:
    Android: When to use Service vs Singleton?
    Android service isn't working as a singleton
    Does startService() create a new Service instance or using the existing one?


    结论:

    1. 当多次startService去启动Service,若Service对象存在,就只调用onStartCommand,若Service对象不存在,创建Service对象。
    2. 服务时天然的单例模式,且可以被销毁。

    相关文章

      网友评论

          本文标题:Service是单例

          本文链接:https://www.haomeiwen.com/subject/ssaqbftx.html