您当前的位置: 首页 >  android

郭梧悠

暂无认证

  • 1浏览

    0关注

    402博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Android context.getSystemService的简单说明

郭梧悠 发布时间:2016-01-11 12:26:34 ,浏览量:1

在android开发过程中这个方法一定不会陌生,比如我们在获取WindowManager和LayoutInflater对象的时候就需要我们调用这个方法。这个方法在context这个抽象类的一个抽象方法,《Context》简单说明这篇简单的博客中我们知道Activity,Servive等组建对应的Context这个接口的实现类是ContextImpl这个类。那么就让我们看看这个ContextImpl是怎么实现getSystemService这个方法的:

 private static final HashMap SYSTEM_SERVICE_MAP =
            new HashMap(); 
@Override
    public Object getSystemService(String name) {
        ServiceFetcher fetcher = SYSTEM_SERVICE_MAP.get(name);
        //调用ServiceFetcher 提供的getService来获取name制定的对象
          return fetcher == null ? null : fetcher.getService(this);
    }

根据android Api我们可以知道name参数可以传递如下的参数:

关注
打赏
1663674776
查看更多评论
立即登录/注册

微信扫码登录

0.0436s