Note that there are some explanatory texts on larger screens.

plurals
  1. POViewGroup.onRestoreInstanceState() not called when inflated programatically
    primarykey
    data
    text
    <p>I've got a <code>ViewGroup</code> which will fire <code>onRestoreInstanceState()</code> if inflated by my activity <code>setContentView()</code>. If I try to inflate it with <code>getLayoutInflater().inflate()</code>, then it won't.</p> <p>I've tried to set an ID for it as said in <a href="https://stackoverflow.com/questions/9714265/restoring-view-hierarchy-from-saved-state-does-not-restore-views-added-programat">Restoring view hierarchy from saved state does not restore views added programatically</a>. I also have an ID in the layout file, and <code>getID()</code> returns the same every activity recreation, yet it won't restore nor save the instance state.</p> <p>How can I overcome this?</p> <p>(Edit) Code I'm using at the moment:</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_ACTION_BAR); setContentView(R.layout.main); //this code will work as intended } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_ACTION_BAR); View content = getLayoutInflater().inflate(R.layout.main, null); setContentView(content); //this code will also work } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_ACTION_BAR); setContentView(R.layout.another_layout); View content = getLayoutInflater().inflate(R.layout.main, null); //now this view won't fire the method } </code></pre> <p>The point is that I don't want to use that view as my layout for the activity. I need to inflate it some other way.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload