3 回答

TA贡献1799条经验 获得超8个赞
getInstance()

TA贡献2016条经验 获得超9个赞
MySingleton.getInstance(Context c) { // // ... needing to create ... sInstance = new MySingleton(c.getApplicationContext());}

TA贡献1859条经验 获得超6个赞
通常不需要子类应用程序。在大多数情况下,静态单节点可以更模块化的方式提供相同的功能。如果您的单例需要全局上下文(例如注册广播接收器),那么检索它的函数可以在第一次构造单例时在内部使用Context.getApplicationContext()。
添加回答
举报