View is not using automatically generated Bundle information.
Searching Stack Overflow yielded no results about it. View is not custom, has unique name id. Is not a duplicated of:
findViewById not working for an include?
FindViewById() not finding View
Other View(s) are working as expected. The only one that is not is added as an include, that is the only difference I could find.
Problem description: View is hidden, Activity is recreated, View is shown.
Details: I have a Button, that uses the default android:onClick
atribute, that invokes a method. This method is working as expected. Then, I "flip" the Android Device, the orientation changes, that causes it to call onSaveInstanceState(Bundle b)
. Information about the Activity is bundled, Activity is destroyed and recreated, then the saved Bundle is sent to onCreate(Bundle b)
as expected.
Then, as per Android Activity, the Bundle restores View(s) states.
Except for a single View
class ExampleActivity extends AppCompatActivity {
public void hide(View view){
view.setVisibility(View.GONE);
}
}
Activity XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/linear_layout_style"
tools:context=".ExampleActivity">
<View style="@style/another_style" />
<include layout="@layout/included_xml" />
<View style="@style/another_style" />
</LinearLayout>
Included XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/linear_layout_style">
<!-- This was supposed to stay hidden after pressed, but it restores in a VISIBLE state -->
<Button
style="@style/the_style"
android:id="@+id/an_unique_id"
android:onClick="hide"
android:text="EXAMPLE: Hide" />
<!-- This is supposed to always be visibile, and it does -->
<Button
style="@style/the_style"
android:onClick="doOtherStuff"
android:text="Example: Always Available">
<requestFocus />
</Button>
</LinearLayout>