Adding ViewGroup to native activity via addContentView from Java displays black frame for period on first call

396 views
Skip to first unread message

Duane Bradbury

unread,
Feb 5, 2014, 12:37:37 PM2/5/14
to andro...@googlegroups.com
Hi all,

I'm trying to resolve a problem I have where a native activity will display a black frame for a short period when I add a ViewGroup to a native activity via addContentView(View, LayoutParams) from Java.  This only seems to happen the very first time the addContentView function is called - the ViewGroup can be removed from it's parent view group and then re-added via the same addContentView call without the same effect occurring again.

From investigations the black frame seems to be that the window/surface gets destroyed when the view hierarchy changes hence the native activity isn't able to draw anything.   Eventually the terminate window and init window commands come through and the native activity re-creates it's display.  This makes sense as I expect a period of time for the commands to come through to the native thread, however I would have thought the black frame issue would present itself each time I called addContentView() but it doesn't so does anyone know why this only happens the first time I call addContentView()?

Also, I've tried a few things to try and workaround the issue but so far not found a good solution.  Is it possible to stop the surface from being destroyed when adding the new ViewGroup in the first place?  If not are there any suggestions as to alternative methods for adding the ViewGroup to the view hierarchy in way that avoids this problem?

As a bit of background and/or in case it's of use, the native activity in this instance is an edited basic OpenGL native activity sample from the (r9c) NDK that I am using for testing purposes and the ViewGroup I am adding from Java is a small hierarchy consisting a ViewGroup and child GLSurfaceView.  This is part of a library project that overlays an OpenGL view on top of the activity and generally works fine with standard Java applications and NDK projects that do now use the native_app_glue code but seems to have a few issues when used via a native activity using the native_app_glue module.

Any ideas or solutions greatly appreciated! :)

Thanks,
Duane

Sylvain

unread,
Feb 7, 2014, 2:43:06 AM2/7/14
to andro...@googlegroups.com
Hi,

I dont know if it would solve your problem, but can you try adding this :

 yourView.setBackgroundColor(Color.TRANSPARENT):


Thanks,

Sylvain

Sylvain

unread,
Feb 7, 2014, 3:57:07 AM2/7/14
to andro...@googlegroups.com
Hello,

Oups, did I suppress myself my answer ?

I am also using opengl in a surfaceview. and adding another view component on top of it make them been black at first.
I got a workaround using :

MyOtherView.setBackgroundColor(Color.TRANSPARENT);

Can you try it ?


Thanks,

Sylvain



Le mercredi 5 février 2014 18:37:37 UTC+1, Duane Bradbury a écrit :

Duane Bradbury

unread,
Feb 26, 2014, 5:48:42 PM2/26/14
to andro...@googlegroups.com
Hi Sylvian,

Apologies for the late response - for some reason I didn't get notified there were any replies to this thread. 

Anyway, I tried your solution of setting the views background colour to be transparent but unfortunately this didn't help in my case. :(

Fortunately, I managed to find a workaround, which was to have the views instantiated via the layout.xml but set to be initially disabled.  I simply re-use these views the first time I come to adding them as an overlay onto the main activity and the surface destroyed issue with consequent black frame doesn't happen anymore. :)

Regards,
Duane
Reply all
Reply to author
Forward
0 new messages