I'm writing an Information Visualization API for Android and ran into a problem trying to place two units of a custom GLSurfaceView
into a Layout. The Custom GLSurfaceView
at this point is simply an extension of the GLSurfaceView
to eliminate possible faults caused by custom methods.
When I have both components added in layout and start the application it runs. But nothing is drawn, seems like it enters an infinite loop. because debug messages inside the Renderers are printed into the LogCat. However, It works perfectly fine if I only use one of the custom GLSurfaceView
components.
I read that there is a problem using GLSurfaceView
in multiple Activities and I suppose it also applies when using two of those components at the same time. I have tried the workaround posted here but cant seem to get it to work either.
I would appreciate any help. I choose to use openGL for the better performance, but if I cant use multiple components at once I guess I'll have to use Canvas instead.
The manifest looks as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="@string/hello" android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.syntronic.vtadlib.VisualizationView android:id="@+id/glview"
android:layout_width="fill_parent" android:layout_height="300px" />
<TextView android:text="@string/hello" android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.syntronic.vtadlib.VisualizationView android:id="@+id/glview2"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>
From the Activity the code is like this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSurfaceView = (VisualizationView) findViewById(R.id.glview);
mSurfaceView2 = (VisualizationView) findViewById(R.id.glview2);
//Enables debug flags for Errors
//mSurfaceView.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);
//mSurfaceView2.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);
mSurfaceView.setRenderer(new CoordinateSystemRenderer());
mSurfaceView2.setRenderer(new CoordinateSystemRenderer());
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mSurfaceView.onPause();
mSurfaceView2.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
mSurfaceView.onResume();
mSurfaceView2.onResume();
}
Am I missing something obvious? Or can someone explain why it doesn't work?
[UPDATE: This answer is no longer correct, as of Android 5.0 (Lollipop). See fadden's answer for a discussion, and links. It was also incorrect as of Android 2.0, and apparently was only an issue for OVERLAPPING surfaces even before then.]
You cannot place 2 SurfaceViews(SV) into one Activity. For understand why you should know how SVs works.
When you create it and place on activity it doesnt actually will be placed in activity (or top of it), instead it will be created behind of current activity with "transparent" view created in that activity.
In Android 4.0 (API 14) there are new View called TextureView There are no way to create something like that View on older platforms.