Activity多次调用getActionBar()返回的是同一个ActionBar对象吗?
2012-08-20 14:39
239 查看
在应用程序开发中,经常看到在Activity中多次调用getActionBar()方法,然后对直接对其进行设置,
次数多了,我不禁想问一句,多次调用getActionBar()并对其进行操作,实际上是用到一个对象了吗?
下面从源码的角度进行分析。
public ActionBar getActionBar() {
initActionBar();
return mActionBar;
}
一看到这,关键的部位出来了,initActionBar(); 继续跟进
private void initActionBar() {
Window window = getWindow();
// Initializing the window decor can change window featureflags.
// Make sure that we have the correct set before performing thetest below.
window.getDecorView();
if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR) ||mActionBar != null) {
return;
}
mActionBar = new ActionBarImpl(this);
}
看到了吧,
if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR)|| mActionBar != null) {
return;
}
当mActionBar不为null的时候,直接返回
所以二者返回的是同一个ActionBar对象。
次数多了,我不禁想问一句,多次调用getActionBar()并对其进行操作,实际上是用到一个对象了吗?
下面从源码的角度进行分析。
public ActionBar getActionBar() {
initActionBar();
return mActionBar;
}
一看到这,关键的部位出来了,initActionBar(); 继续跟进
private void initActionBar() {
Window window = getWindow();
// Initializing the window decor can change window featureflags.
// Make sure that we have the correct set before performing thetest below.
window.getDecorView();
if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR) ||mActionBar != null) {
return;
}
mActionBar = new ActionBarImpl(this);
}
看到了吧,
if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR)|| mActionBar != null) {
return;
}
当mActionBar不为null的时候,直接返回
所以二者返回的是同一个ActionBar对象。
相关文章推荐
- 前台使用ajax 调用action方法,返回一个对象List集合的json
- 调用getActionBar()总会报Call requires API level 11 (current min is 8): android.app.Activity#getActionBar
- 【转】调用getActionBar()报Call requires API level 11 (current min is 8): android.app.Activity#getActionBar
- Android ActionBar 返回上一个Activity
- 为什么多次调用同一个对象的HashCode方法返回不一样
- IE7中get多次请求返回同一个值得问题
- Struts2 Action中调用get***命名方法,并且返回json,执行出错
- android开发(26) 和其他应用交换数据方式一,使用intent指定自定义action调用其他程序里的activity,并获得其返回的结果
- getSupportActionBar() 函数总是返回 null 的解决
- getActionBar() 返回空指针问题
- 隐藏actionBar, 报错 getActionBar.hide() 运行时java.lang.NullPointerException
- SpringMVC学习系列(3) 之 URL请求到Action的映射规则 在系列(2)中我们展示了一个简单的get请求,并返回了一个简单的helloworld页面。本篇我们来学习如何来配置一个acti
- activity启动模式,返回上一个activity时又调用一次onCreate()方法
- 使用MVC中的HtmlHelper对象的ActionLink方法,实现一个Javascript:void(0)效果,去调用一个JS方法
- Android与Unity交互调用mUnityPlayer.quit()方法退出返回上一个Activity界面
- 在fragment中设置bar,getSupportActionbar()返回null,添加up action失败的原因。
- getActionBar()返回为空 空指针错误 Caused by: java.lang.NullPointerException
- Java Runtime error: java.lang.NoSuchMethodError: CheckUserActivity.getActionBar
- scala调用java的方法,返回了一个对象链表List<Student>,在scala中遍历该链表获取指定Student的名字name
- Ajax使用Action中返回的Json数据的完整实例(二):action内将一个实体对象转化为json并返回