如何使用Singleton模式在Android项目? [英] How to use the Singleton pattern in an Android project?
本文介绍了如何使用Singleton模式在Android项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道辛格尔顿,但在Android的项目,我无法使用它。我在Android的初学者。 请告诉我如何与放大器;在这里我们可以在大数据的Android项目使用的单例。我已经使用了简单的值。
I know about Singleton, but I can't use it in an Android project. I am a beginner in Android. Please tell me how & where we can use Singleton in an Android project for Large Data. I have used it for simple values.
推荐答案
辛格尔顿在Android是一样的辛格尔顿在Java中:
Singleton in Android is the same as Singleton in Java:
有一个基本的单例类的例子:
A basic Singleton class example:
public class AppManager
{
private static AppManager _instance;
private AppManager()
{
}
public synchronized static AppManager getInstance()
{
if (_instance == null)
{
_instance = new AppManager();
}
return _instance;
}
}
这篇关于如何使用Singleton模式在Android项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文