从文档中直接拉出来
Enums often require more than twice as much memory as static constants. You should strictly avoid using enums on Android.
http://developer.android.com/training/articles/memory.html#Overhead
编辑:
也是罗曼盖伊谈话之一的幻灯片
https://speakerdeck.com/romainguy/android-memories?slide=67
int上的操作比枚举上的操作快许多倍.
为自己判断.每次创建枚举时,您都要创建一个至少:
1) Class-loader for it.
2) You keep this object in memory.
3) Since enum is static anonymous class - it will always hang in your memory (sometimes even after you close the application.)
Run Code Online (Sandbox Code Playgroud)
关于Service.在这个类中,标志主要用于比较并将结果返回给上面的类(ContextWrapper).但基本上,如果你深入研究Android SDK的内容,你会发现自己几乎所有这些标志都用于通过轮换操作.
即使在Java中也使用JDK中的二进制移位操作:
/**
* Max capacity for a HashMap. Must be a power of two >= MINIMUM_CAPACITY.
*/
private static final int MAXIMUM_CAPACITY = 1 << 30;
Run Code Online (Sandbox Code Playgroud)
您也可以在Android SDK中查看Window类
/**
* Set the container for this window. If not set, the DecorWindow
* operates as a top-level window; otherwise, it negotiates with the
* container to display itself appropriately.
*
* @param container The desired containing Window.
*/
public void setContainer(Window container) {
mContainer = container;
if (container != null) {
// Embedded screens never have a title.
mFeatures |= 1<<FEATURE_NO_TITLE;
mLocalFeatures |= 1<<FEATURE_NO_TITLE;
container.mHasChildren = true;
}
}
/** The default features enabled */
@SuppressWarnings({"PointlessBitwiseExpression"})
protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
(1 << FEATURE_CONTEXT_MENU);
Run Code Online (Sandbox Code Playgroud)
减少内存消耗.
由于按位操作,工作速度更快.
| 归档时间: |
|
| 查看次数: |
1773 次 |
| 最近记录: |