android开发为什么不使用Spring这样的框架?

android 开发中也有一些实现了ioc功能的,比如butterKnife、dragger,Spring的主要的一份方面就是提供ioc的功能。而且S…
关注者
56
被浏览
65,288

10 个回答

Android本身就是个框架

在安卓开发中,尽量不要使用java的库,因为java库没有在移动终端环境进行相应的优化。也尽量不要使用android的依赖注入库,因为会有占内存大的问题。下边进行详细解释。注:以下英文部分来自谷歌官方文档。

首先说尽量不要使用java库

1.Be careful about using external libraries

External library code is often not written for mobile environments and can be inefficient when used for work on a mobile client. At the very least, when you decide to use an external library, you should assume you are taking on a significant porting and maintenance burden to optimize the library for mobile. Plan for that work up-front and analyze the library in terms of code size and RAM footprint before deciding to use it at all.

外部的java库代码没有在移动环境上进行优化,所以尽量不要使用。

然后说关于android 上的依赖注入库,比如dagger,Guice。是要尽量避免使用的。

2.Avoid dependency injection frameworks

Using a dependency injection framework such as Guice or RoboGuice may be attractive because they can simplify the code you write and provide an adaptive environment that's useful for testing and other configuration changes. However, these frameworks tend to perform a lot of process initialization by scanning your code for annotations, which can require significant amounts of your code to be mapped into RAM even though you don't need it. These mapped pages are allocated into clean memory so Android can drop them, but that won't happen until the pages have been left in memory for a long period of time.

虽然会简化代码,但是在检查代码的注解时需要把代码都加载到内存中,会使得app占用内存大。


如果app占用内存大,那很有可能在后台时候会被默默杀掉。


至于问题中将spring和json作比较。。。我只能说json只是一种数据格式而已。完全没看懂题主在比较什么。