在我的应用程序中,我使用自定义窗口标题。并且在后按时我正在调用相同活动的 oncreate 方法。我遇到以下异常我如何调用相同活动的 oncreate 方法 onbackpressed-
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
代码是-
private Bundle mBundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
mBundle=savedInstanceState;
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
.
.
.
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
//super.onBackPressed();
if(backFlag){
onCreate(mBundle);
backFlag=false;
}else{
finish();
}
}
答案- 我得到了问题的解决方案。在背压我再次调用相同的活动
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
//super.onBackPressed();
if(backFlag){
backFlag=false;
Intent i=new Intent(this,MainActivity.class);
startActivity(i);
finish();
}else{
finish();
}
}