如何在Android项目中使用Singleton模式?
我知道Singleton,但我无法在Android项目中使用它。 我是Android的初学者。 请告诉我在大型数据的Android项目中如何以及在哪里使用Singleton。 我用它来表示简单的值。
Android中的Singleton与Java中的Singleton相同:
一个基本的Singleton类示例:
public class AppManager { private static AppManager _instance; private AppManager() { } public synchronized static AppManager getInstance() { if (_instance == null) { _instance = new AppManager(); } return _instance; } }
- 对于“大数据”使用数据库。 Android为您提供SQlite。
- 当然你可以在Android中使用Singletons。 是什么让你认为你做不到?
有关单例模式的更多信息,请阅读http://en.wikipedia.org/wiki/Singleton_pattern
有关SQLite的更多信息,请阅读: http : //developer.android.com/guide/topics/data/data-storage.html#db