0

I have the following in OnCreate

  requestWindowFeature(Window.FEATURE_NO_TITLE);

On resume is:

  @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);
    }

It throws the exception when activity resumes: rewuestFeature must be called before adding content. Whats wrong ?

Sanjay Singh
  • 349
  • 5
  • 18

3 Answers3

2

You need to call requestWindowFeature(Window.FEATURE_NO_TITLE); before setContentView in onCreate

PgmFreek
  • 6,374
  • 3
  • 36
  • 47
  • Its being called before setContentView in onCreate. It works fine normally but crashing while resuming. – Sanjay Singh Dec 24 '13 at 10:51
  • Its is because when you call onCreate on resume requestWindowFeature(Window.FEATURE_NO_TITLE); will be invoked after setting the contentview. This is because onCreate will be called twice and during the first call content view will be set in the activity. You must not call requestWindowFeature(Window.FEATURE_NO_TITLE) on onResume. – PgmFreek Dec 24 '13 at 10:55
  • requestWindowFeature(Window.FEATURE_NO_TITLE) is called only in onCreate(). onResume() is calling onCreate(). I have edited question with complete code on onCreate(). – Sanjay Singh Dec 24 '13 at 11:02
  • That means on create will be called twice.And on the second call requestWindowFeature(Window.FEATURE_NO_TITLE) will be called after setting the contentView – PgmFreek Dec 24 '13 at 11:48
1

If you were set requestWindowFeature(Window.FEATURE_NO_TITLE); after onCreate() method then you have to remove that and set

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

}
Piyush
  • 18,895
  • 5
  • 32
  • 63
0

I found this working - I got this idea only after reading all comments and solutions offered. Thanks to all who responded.

      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);
       }
Sanjay Singh
  • 349
  • 5
  • 18