Binding a Service to an android.app.Activity vs Binding it to an android.app.Application

前端 未结 2 1436
梦谈多话
梦谈多话 2020-12-30 03:44

Is there any fundamental difference in binding a service to an android.app.Activity vs binding it to an android.app.Application. I want to

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 04:04

    No. There is no fundamental difference.

    That said, subclassing android.app.Application is a very good place to store global/state data. There is only one instance and everything that derives from Context has access to it.

    I'm also sure that binding a service to an application will result in some odd lifetimes if you aren't careful. What I mean is that even though your app is out of sight and has no activities alive, your application could still exist because your service still exists. Your service still exists because your application still exists. You would have to manually shut down the service based on some event other than onDestroy.

提交回复
热议问题