zoukankan      html  css  js  c++  java
  • Android中的getActivity()方法

      /**
        * Return the {@link FragmentActivity} this fragment is currently associated with.
        * May return {@code null} if the fragment is associated with a {@link Context}
        * instead.
        *
        * @see #requireActivity()
        */
    @Nullable
    final public FragmentActivity getActivity() {
        return mHost == null ? null : (FragmentActivity) mHost.getActivity();
    }
    

    返回一个和此fragment绑定的FragmentActivity或者其子类的实例(即和当前碎片相关联的活动实例)。相反,如果此fragment绑定的是一个context的话,可能会返回null。因为getActivity()大部分都是在fragment中使用到,而fragment需要依赖于activity,所有我们在fragment里头需要做一些动作,比如启动一个activity,就需要拿到activity对象才可以启动,而fragment对象是没有startActivity()方法的。

    这个方法主要是用来进行碎片和活动之间的通信。

  • 相关阅读:
    vue零散知识
    vue router 和 组件生命周期的理解
    未搞懂的问题
    前端问题总结
    垂直居中
    css,js加载阻塞页面渲染的理解
    node 学习
    自定义事件
    学习react 遇到的问题
    [AHOI2001]彩票摇奖
  • 原文地址:https://www.cnblogs.com/fanlumaster/p/13735945.html
Copyright © 2011-2022 走看看