android - BaseActivity重写了onCreate方法,继承它的类如果不写onCreate()方法
本文介绍了android - BaseActivity重写了onCreate方法,继承它的类如果不写onCreate()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
BaseActivity重写了onCreate方法,继承它的类如果不写onCreate()方法,为什么还会执行父类BaseActivity的onCreate方法?我没重写DrawDraftActivity 里的oncreate(),为什么 titleBar.setTitleTxt("123");有作用?
public class DrawDraftActivity extends BaseActivity {
@Override
protected int getLayoutId() {
return R.layout.activity_draw_draft;
}
@OnClick(R.id.btn_edit)
void click() {
startActivity(new Intent(this, DrawActivity.class));
}
@Override
protected void afterBind() {
super.afterBind();
titleBar.setTitleTxt("123");
}
}
public abstract class BaseActivity extends AppCompatActivity {
protected Activity act;
protected Dialog progressDialog;
protected CommonTitleBar titleBar;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
act = this;
setContentView(getLayoutId());
setTitleBar();
ButterKnife.bind(this);
AppManager.getManager().add(this);
EventBus.getDefault().register(this);
afterBind();
}
private void setTitleBar() {
titleBar = (CommonTitleBar) findViewById(R.id.title_layout);
if (titleBar != null)
titleBar.setLeftBtnOnclickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
protected abstract int getLayoutId();
protected void afterBind() {
}
@Subscribe
public void defaultEventHandler(DefaultEvent event) {
// not handle
}
protected void postEvent(Object obj) {
EventBus.getDefault().post(obj);
}
}
解决方案
额。。。==,你是Java没有学好么?有本事别在子类里调用super啊==
这篇关于android - BaseActivity重写了onCreate方法,继承它的类如果不写onCreate()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文