Imagination PowerVR SDK Blog

how to add android GUI View over NativeActivity ?



I am having a bit of struggle trying to add a GUI widget over the NativeActivity or GLES2 window !!

I am having a frameLayout object(main.xml) which I want to add, but doing NativeActivity.addContentView is not showing anything !!

Here is the Java side code…please help !!

public class MyApp extends NativeActivity  {

public void OnCreate(Bundle savedInstanceState){
LayoutInflater inflater = getLayoutInflater();
View tmpView;
tmpView = inflater.inflate(R.layout.main, null);
getWindow().addContentView(tmpView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,


HI Madan ,

Have you been able to resolve this issue?



Hi Joe,

I got this working ! No worries.
The solution was to have another activity window on top of native activity window and reroute the touch from Java code through JNI to my c++ code :wink:  This gave me now complete flexibility to add GUI design, google Ads etc in this new activity window !


I am facing the same problem. Need to have custom android cuntrols over OpenGL NativeActivity. Any chance you can share code relating opening up a transparent window on top of NativeActivity? What about using PowerVRShell with GLSurfaceView. Does Anyone know how to do it?


Hello , in fact the Shell OS class is quite well design and portable. you could call your dialog box directly from shellos.cpp (the default native activity is use in the sdk but it s a good idea to extend it).

from my mind i will write

PVRShellInit* init = (PVRShellInit*) app->userData;

init->showDialog(); //

that is all from c++ point of view .

and in the java code :

public void showDialog()


runOnUiThread(new Runnable() {

public void run()


DialogFragment newFragment = MyAlertDialogFragment.newInstance(

R.string.action_settings);, “dialog”);




i think the key things is to understand what do the Native App Glue and the life cycle of the app .

Native subclassing is then quite handy.



ok… so using DialogFragment makes sense in that case. For backwards compatibility u can use the one inside the Support library.

If you want to have it transparent, the following can be used.

from hear i guess you need to at least customize the shell to not pause drawing if window focus is lost. Will give this one an approach and post results.

I guess it’s also possible to make the NativeActivity’s Window transparent and offset and size the OpenGL drawing. Will also have a look at this.

Still, is there a way to switch to GLSurfaceView or something. Because we really need to mix with android java UI and that would be most comfortable. I thought i read something in this forum about someone mixing the current ShellOS with an earlier one because you previously didn’t use NativeActivity. Is that correct? Will try to find the post I am talking about.

Thank you so far.



about your question :

what about using PowerVRShell with GLSurfaceView. Does Anyone know how to do it?

it s “doable” but it s sad because the PVRShellOS provide all the EGL management as well , and it s work on IOS android BB10

1/ using the default one work well by taking care of struct android_app* state to interroperate java to c++ .

2/ write your own glue is good as well and just replace the one use in the PVRShellOS.h .

by my side i change the #include localized in the PVRShellOS.h but only because i have special need , the default one is ready to go as is.The result is i can mix whatever i want .

The PVRShellOS deal with event that are plateform dependant ,

PVRShellImpl store all business method independant of the plafeform.

then All events function are define on the implementation of this classes PVRShellOS.cpp :

// Setup our android state

PVRShellInit init;

state->userData = &init;

state->onAppCmd = handle_cmd;

state->onInputEvent = handle_input;

from handle_input, you can the redirect call from java–>c++ or c++ —> java from the appropriate touch event or callback as you wish.

The subclassing method work well with native activity .

just a sharing .

david g



HI Marcus,

My solution applies to android side with no changes to c++/PVR code.

Here are steps.

Android side

  1. create a GUIActivity class which will handle interactions on the android side and will either use them or pass them to the underlying AppInterface class

    public class GUIActivity extends Activity

  2. create an AppInterface class. This is the class which the PVR will create on initialization.

    public class AppInterface extends NativeActivity

  3. AppInterface is first created. So you must create GUIActivity when this is created

    //inside AppInterface


    protected void onCreate(Bundle savedInstanceState){


    context = this.getApplication().getApplicationContext();

    Intent startNewActivityOpen = new Intent(this, GUIActivity.class);



  4. load PVR dll or .so inside AppInterface class

    //paste this code and change the library name from PVRPlatform to whatever you use

    static {

    try {

    System.out.println(“loading PVRPlatform …”);


    System.out.println(“PVRPlatform load success”);


    catch(UnsatisfiedLinkError e) {

    System.out.println(“got unsatisfiedlinkerror boss”);


    catch(SecurityException e) {

    System.out.println(“got security exception boss”);



  5. mention in the manifest your acitivites

    <activity android:name=“com.powervr.GLES2App.AppInterface"






    <activity android:name=“com.powervr.GLES2App.GUIActivity"




  6. make sure your GUIActivity is a transparent theme which means its background is always transparent.
  7. now you have to play with GUI controls. You can add menu into GUIActivity which gets launched first. Here I have a start button, which will call Init into appInterface and launch the game and at the same make make GUIActivity clear of all controls.

  8. you can pass touch events from GUIActivity down to AppInterface like this


    public boolean onTouchEvent(MotionEvent ev) {

    if (isViewInGameMode == true) {

    if (ev.getAction() == MotionEvent.ACTION_DOWN)

    AppInterface.OnTouchStart(ev.getX(), ev.getY());

    else if (ev.getAction() == MotionEvent.ACTION_MOVE)

    AppInterface.OnTouchUpdate(ev.getX(), ev.getY());

    else if (ev.getAction() == MotionEvent.ACTION_UP)

    AppInterface.OnTouchEnd(ev.getX(), ev.getY());

    else {

    System.out.println("action " + ev.getAction()
  • " unaccounted for in OnTouchEvent");



    return super.onTouchEvent(ev);


    Let me know if you hit any snags.