绑定服务到android.app.Activity VS它绑定到android.app.Application [英] Binding a Service to an android.app.Activity vs Binding it to an android.app.Application

查看:171
本文介绍了绑定服务到android.app.Activity VS它绑定到android.app.Application的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有任何的基本的在绑定到 android.app.Activity 服务VS它绑定到不同的 android.app.Application 。我想绑定的服务给应用程序,因为我要保持我的所有活动的重复它的一些全局状态/数据应用程序来代替。

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 bind the service to an Application because I want to keep some global state/data in the Application instead of duplicating it in all my activities.

感谢。

推荐答案

没有。没有的基本的区别。

这是说,继承android.app.Application是存放全局/状态数据的非常的好地方。世界上只有一个实例,一切源于上下文访问它。​​

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.

我也相信一个服务绑定到应用程序,将导致一些奇怪的寿命,如果你不小心。我的意思是,即使你的应用程序是淡出人们的视线,也没有活动活着,你的应用程序可能仍然存在,因为你的服务仍然存在。您的服务仍然存在,因为你的应用程序仍然存在。你必须基于某些事件以外的onDestroy手动关闭该服务。

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.

这篇关于绑定服务到android.app.Activity VS它绑定到android.app.Application的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆