美文网首页android学习笔记
如果context有上下文环境,怎么使用单利模式

如果context有上下文环境,怎么使用单利模式

作者: 鼾声鼾语 | 来源:发表于2020-01-07 15:03 被阅读0次

话不多说,直接上代码

 public static App instances;
   public static App getInstances(){
        return instances;
    }

在构造函数中添加:
instances = this;

这个时候,你就可以通过getInstances方法获取到单利对象了,是不是很方便呢。

相关文章

网友评论

    本文标题:如果context有上下文环境,怎么使用单利模式

    本文链接:https://www.haomeiwen.com/subject/diwractx.html