[android-developers] Re: OpenGL SurfaceView renders black on first start - works after orientation change
I have "solved" it with an ugly hack. This is not a solution but a workaround until I find a better way: private GLSurfaceView mGLSurfaceView; private static boolean firstCreate = true; /* * Constructors */ /* * Methods */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create our Preview view and set it as the content of our // Activity mGLSurfaceView = new GLSurfaceView(this); mGLSurfaceView.setRenderer(new ContactsRenderer(this)); setContentView(mGLSurfaceView); if (firstCreate) { setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); firstCreate = false; } } On Apr 1, 4:10 pm, Ulrich Scheller wrote: > I have an Activity that was created based on the TriangleRenderer > example. It works flawlessly as a standalone project, but when I use > it as the tab of a tabhost there is a problem. At startup the whole > activity is just black - I can get touch events and do everything else > but it doesnt show anything. When I change the orientation (and > therefore recreate the activity) it all works well. > > Maybe the problem comes from the View focus. My SurfaceView is not > focused when created inside of the tabhost. I tried to fiddle around > with the methods available in my onCreate() and onPostCreate(), but > couldnt find a way to get the SurfaceView focused. > > The following sourcecode blocks in the guardedRun() method because > needToWait() is true because !mHasFocus is true. If I exclude the ! > mHasFocus, it goes on but shows a black View anyways. > > Do you have any idea why it does work after orientation change, but > not at the first startup? > > The Activity looks quite simple: > === > > @Override > protected void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > // Create our Preview view and set it as the content of our > // Activity > mGLSurfaceView = new GLSurfaceView(this); > mGLSurfaceView.setRenderer(new ContactsRenderer(this)); > setContentView(mGLSurfaceView); > System.out.println("focused: " + mGLSurfaceView.isFocused() + > " focusable: " + mGLSurfaceView.isFocusable()); > } > > @Override > protected void onResume() { > // Ideally a game should implement onResume() and onPause() > // to take appropriate action when the activity looses focus > super.onResume(); > mGLSurfaceView.onResume(); > } > > @Override > protected void onPause() { > // Ideally a game should implement onResume() and onPause() > // to take appropriate action when the activity looses focus > super.onPause(); > mGLSurfaceView.onPause(); > } > > Thats my SurfaceView Class: > == > /** > * An implementation of SurfaceView that uses the dedicated surface > for > * displaying an OpenGL animation. This allows the animation to run > in a > * separate thread, without requiring that it be driven by the update > mechanism > * of the view hierarchy. > * > * The application-specific rendering code is delegated to a > GLView.Renderer > * instance. > */ > public class GLSurfaceView extends SurfaceView implements > SurfaceHolder.Callback { > private float touch_x = 0; > private long touch_time = 0; > private int touch_selected = 0; > private Context contactScreen; > > public GLSurfaceView(Context context) { > super(context); > this.contactScreen = context; > init(); > } > > public GLSurfaceView(Context context, AttributeSet attrs) { > super(context, attrs); > init(); > } > > private void init() { > setFocusable(true); > // Install a SurfaceHolder.Callback so we get notified when > the > // underlying surface is created and destroyed > mHolder = getHolder(); > mHolder.addCallback(this); > mHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU); > } > > public SurfaceHolder getSurfaceHolder() { > return mHolder; > } > > public void setGLWrapper(GLWrapper glWrapper) { > mGLWrapper = glWrapper; > } > > public void setRenderer(Renderer renderer) { > mGLThread = new GLThread(renderer);
[android-developers] OpenGL SurfaceView renders black on first start - works after orientation change
I have an Activity that was created based on the TriangleRenderer example. It works flawlessly as a standalone project, but when I use it as the tab of a tabhost there is a problem. At startup the whole activity is just black - I can get touch events and do everything else but it doesnt show anything. When I change the orientation (and therefore recreate the activity) it all works well. Maybe the problem comes from the View focus. My SurfaceView is not focused when created inside of the tabhost. I tried to fiddle around with the methods available in my onCreate() and onPostCreate(), but couldnt find a way to get the SurfaceView focused. The following sourcecode blocks in the guardedRun() method because needToWait() is true because !mHasFocus is true. If I exclude the ! mHasFocus, it goes on but shows a black View anyways. Do you have any idea why it does work after orientation change, but not at the first startup? The Activity looks quite simple: === @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create our Preview view and set it as the content of our // Activity mGLSurfaceView = new GLSurfaceView(this); mGLSurfaceView.setRenderer(new ContactsRenderer(this)); setContentView(mGLSurfaceView); System.out.println("focused: " + mGLSurfaceView.isFocused() + " focusable: " + mGLSurfaceView.isFocusable()); } @Override protected void onResume() { // Ideally a game should implement onResume() and onPause() // to take appropriate action when the activity looses focus super.onResume(); mGLSurfaceView.onResume(); } @Override protected void onPause() { // Ideally a game should implement onResume() and onPause() // to take appropriate action when the activity looses focus super.onPause(); mGLSurfaceView.onPause(); } Thats my SurfaceView Class: == /** * An implementation of SurfaceView that uses the dedicated surface for * displaying an OpenGL animation. This allows the animation to run in a * separate thread, without requiring that it be driven by the update mechanism * of the view hierarchy. * * The application-specific rendering code is delegated to a GLView.Renderer * instance. */ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback { private float touch_x = 0; private long touch_time = 0; private int touch_selected = 0; private Context contactScreen; public GLSurfaceView(Context context) { super(context); this.contactScreen = context; init(); } public GLSurfaceView(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init() { setFocusable(true); // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed mHolder = getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU); } public SurfaceHolder getSurfaceHolder() { return mHolder; } public void setGLWrapper(GLWrapper glWrapper) { mGLWrapper = glWrapper; } public void setRenderer(Renderer renderer) { mGLThread = new GLThread(renderer); mGLThread.start(); } public void surfaceCreated(SurfaceHolder holder) { mGLThread.surfaceCreated(); } public void surfaceDestroyed(SurfaceHolder holder) { // Surface will be destroyed when we return mGLThread.surfaceDestroyed(); } public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { // Surface size or format has changed. This should not happen in this // example. mGLThread.onWindowResize(w, h); } /** * Inform the view that the activity is paused. */ public void onPause() { mGLThread.onPause(); } /** * Inform the view that the activity is resumed. */ public void onResume() { mGLThread.onResume(); } @Override public boolean onTouchEvent(MotionEvent event) { ContactsRenderer render = (ContactsRenderer) mGLThread.mRenderer; if (event.getAction() == MotionEvent.ACTION_DOWN) { touch_x = event.getX(); touch_time = System.currentTimeMillis(); touch_selected = render.getSelectedContact(); return true; } else { float diff = touch_x - event.getX(); long time_diff = System.currentTimeMillis() - touch_time; if (event.getAction() == MotionEvent.ACTION_MOVE){ render.move(-diff/1000f); touch_x = event.getX(); return true; } else if (event.getAction() == M
[android-developers] Re: Service permission and AndroidManifest.xml errors
I was having the same error message and didnt know what to do about it at first. The mistake was that I was extending the ListActivity, not just an Activity. On Feb 10, 2:04 pm, Android wrote: > Hi, > > Ihavecreated two .apk as client and server. My client Acticity wants > to invoke the Service of my Server .apk. I used the AIDL and IPC > mechanism to communicate betwwen the Client and server. > > My Client code was compiled fine but during Server compliation it was > giving bunch of errors as : > 02-10 17:40:22.310: WARN/dalvikvm(246): threadid=3: thread exiting > with uncaught exception (group=0x40010e28) > 02-10 17:40:22.310: ERROR/AndroidRuntime(246): Uncaught handler: > thread main exiting due to uncaught exception > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): > java.lang.RuntimeException: Unable to start activity ComponentInfo > {oem.android.proj2/oem.android.proj2.RemoteServiceBinding}: > java.lang.RuntimeException:YourcontentmusthaveaListViewwhoseidattributeis > 'android.R.id.list' > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > 2140) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: > 2156) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.app.ActivityThread.access$1800(ActivityThread.java:112) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.os.Handler.dispatchMessage(Handler.java:88) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.os.Looper.loop(Looper.java:123) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.app.ActivityThread.main(ActivityThread.java:3742) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > java.lang.reflect.Method.invokeNative(Native Method) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > java.lang.reflect.Method.invoke(Method.java:515) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run > (ZygoteInit.java:739) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > dalvik.system.NativeStart.main(Native Method) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): Caused by: > java.lang.RuntimeException:YourcontentmusthaveaListViewwhoseidattributeis > 'android.R.id.list' > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.app.ListActivity.onContentChanged(ListActivity.java:236) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > com.android.internal.policy.impl.PhoneWindow.setContentView > (PhoneWindow.java:230) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.app.Activity.setContentView(Activity.java:1569) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > oem.android.proj2.RemoteServiceBinding.onCreate > (RemoteServiceBinding.java:35) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: > 1122) > 02-10 17:40:22.330: ERROR/AndroidRuntime(246): at > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > 2103) > > = > > My AndroidManifest.xml file are as below: > > Server Manifest file: > > android:label="@string/app_name" > android:exported="true" > android:enabled="true" > > android:permission="oem.android.permission.READ_OWNER_DATA"> > > > > Client Manifest file: > > > android:label="@string/app_name"> > > > android:name="android.intent.category.LAUNCHER" /> > > > > > Can some plz help me to resolve the errors. > > To communicate between two normal .apks what permission should be > prefered, for time being i am using > android.permission.READ_OWNER_DATA, is that ok. > > -Kumar --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Switch to a SurfaceView from a WebView
Hi, I want to show a WebView with some information at the start of my application. After clicking a button, this view should disappear for the SurfaceView of the app. In the following code I try to do this in several ways. What happens is that the WebView disappears, but the SurfaceView doesnt show. I can click on the touchscreen and get events for it, but I dont see anything on the display. What am I doing wrong? @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Handler mHandler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); setContentView(R.layout.laska_layout); mLaskaView = (LaskaView) findViewById(R.id.laska); mLaskaView.setVisibility(View.VISIBLE); mInfoView.setVisibility(View.INVISIBLE); mInfoView.destroy(); mLaskaView.bringToFront(); mLaskaView.requestFocus(); mLaskaView.getHolder().getSurface().show(); mLaskaThread.doDraw(); } }; // turn off the window's title bar requestWindowFeature(Window.FEATURE_NO_TITLE); // tell system to use the layout defined in our XML file setContentView(R.layout.laska_layout); // get handles to the LaskaView from XML, and its LaskaThread mLaskaView = (LaskaView) findViewById(R.id.laska); mLaskaThread = mLaskaView.getThread(); // give the LaskaView a handle to the TextView used for messages mLaskaView.setTextView((TextView) findViewById(R.id.text)); ... setContentView(R.layout.info_layout); mInfoView = (InfoView) findViewById(R.id.info); mInfoView.setLaskaHandle(mHandler); } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Any way to have two MediaRecorders recording at once?
You could record one audio stream and copy the desired parts into two new streams later on. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---