android中最常使用的設計模式就是單例模式;
內部類形式
public class Singleton {
//私有化構造器
private Singleton() {}
//內部類實現單例模式
private static class SingletonHolder {
private static SingletonHolder INSTANCE = new SingletonHolder();
}
public static SingletonHolder getInstance() {
return SingletonHolder.INSTANCE;
}
}