For some reason that I don’t understand, when I create my SurfaceView from an XML layout the surface is cleared every refresh. But if I just initalize it in code without the XML the drawn surface is retained.
If I initialize the SurfaceView like this it is drawn blank every refresh:
app = (App) findViewById(R.id.app);
app.setActivity(this);
If I initialize the SurfaceView like this the surface’s drawing is retained every refresh:
app = new App(this);
setContentView(app);
app.setActivity(this);
Here is the XML layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
android:clickable="true">
<com.threedtopo.someapp.android.app
android:id="@+id/app"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
android:clickable="true" />
</LinearLayout>
Any insight would be appreciated, thanks!
Edit: This is how the root view is being initialized in the first example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<!-- <TextView -->
<EditText
android:id="@+id/hidden_text"
android:inputType="textLongMessage"
android:autoText="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="true"
android:visibility="gone"
android:focusable="true"
android:focusableInTouchMode="true"
/>
</LinearLayout>
<ViewSwitcher
android:id="@+id/switcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/splash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/splashscreen" />
<com.threedtopo.someapp.android.app android:id="@+id/app"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:clickable="true" />
</ViewSwitcher>
<LinearLayout
android:id="@+id/keyboard_layout"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<android.inputmethodservice.KeyboardView
android:id="@+id/keyboard"
android:visibility="gone"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</RelativeLayout>
Thanks to harism this has been solved. Apparently setting the background property in the XML file causes the SurfaceView to be cleared each draw.