活动在简历上崩溃

时间:2013-12-24 10:42:09

标签: android android-activity

我在OnCreate中有以下内容

  requestWindowFeature(Window.FEATURE_NO_TITLE);

简历是:

  @Override
  public void onResume(){

     onCreate(savedInstanceState);
     super.onResume();

  }



    @Override
    public void onCreate(Bundle savedInstanceState) {


    super.onCreate(savedInstanceState);
    this.savedInstanceState = savedInstanceState;
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    context = this;
    ps = PuzzleState.getInstance();
    setContentView(R.layout.activity_pack_list);
    }

它会在活动恢复时抛出异常:必须在添加内容之前调用rewuestFeature。怎么了?

3 个答案:

答案 0 :(得分:2)

您需要在requestWindowFeature(Window.FEATURE_NO_TITLE);

中的setContentView之前致电onCreate

答案 1 :(得分:1)

如果在onCreate()方法之后设置了 requestWindowFeature(Window.FEATURE_NO_TITLE); ,则必须将其删除并设置

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.gallery_item);

}

答案 2 :(得分:0)

我发现这个工作 - 只有在阅读了所有提供的评论和解决方案后才能得到这个想法。感谢所有回复的人。

      private static boolean first = true;

      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.savedInstanceState = savedInstanceState;

      if(first){

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        first = false;
      }


      context = this;
      ps = PuzzleState.getInstance();
      setContentView(R.layout.activity_pack_list);
       }