onCreate function never called in activity using OpenGL

29 Views Asked by At

I'm trying to write a plugin for an app in Android Studio using a separate tool that generates C++ files and uses openGL to create symbols. The code I have runs fine as a standalone app, however I'm trying to run it as a plugin. Whenever I try to run it, I get a blank screen. The view seems to be displaying fine but none of the graphics show up. I've narrowed it down to the onCreate method.

Basically I have: a java file that creates a view and inflates it to be linked to a layout file:

pluginView = PluginLayoutInflater.inflate(context, R.layout.activity_glandroid, null);

when the plugin is clicked on, there's a function that is called to show the view:

if (action.equals(SHOW_PLUGIN)) {
            showDropDown(pluginView, FULL_WIDTH, FULL_HEIGHT, FULL_WIDTH,
                    FULL_HEIGHT, false, this);
        }

that part isn't as important but I felt the need to include it. Both of those seem to be working fine.

I have this in my AndroidManifest.xml that calls the java file that initializes the openGL code. Wherever "appName" is mentioned, that is the main app that we're trying to write a plugin for.:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.appName.android.plugintemplate.plugin"
    tools:ignore="GoogleAppIndexingWarning">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-feature android:glEsVersion="0x00020000" android:required="true" />

    <application 
        android:allowBackup="false"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:description="@string/app_desc"
        android:extractNativeLibs="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <meta-data android:name="plugin-api" android:value="${ApiVersion}"/>
        <meta-data android:name="app_desc" android:value="@string/app_desc"/>


       <!-- This fictitious activity entry allow for appName 4.6.0.2 and newer to perform 
            plugin discovery  android devices.  If this is removed, the plugin will 
            not be able to be discovered or loaded.  -->
       <activity android:name="com.disti.glandroid.GlAndroid" tools:ignore="MissingClass"
           android:label="@string/app_name"
           android:exported="true">
           <intent-filter>
              <action android:name="com.appName.app.component" />
               <action android:name="android.intent.action.MAIN" />

               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>

    </application>

</manifest>

I also have this in my xml layout file that is being called:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.glAndroid" >

</RelativeLayout>

From there, the openGL file has this at the beginning of the file:

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
//import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

import com.SurfaceView;

public class GlAndroid extends Activity
{
    private GlSurfaceView myView;
    private static final String TAG = "GlActivity";


    private static GlAndroid _instance = null;
    public static GlAndroid GetInstance() { return _instance; }

    /**
     * Called when the Activity is first created
     */
    @Override
    protected void onCreate( Bundle savedInstanceState )
    {
        Log.e(TAG, "onCreate");
        super.onCreate( savedInstanceState );
        Log.d(TAG, "onCreate");

        requestWindowFeature( Window.FEATURE_NO_TITLE );
        getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN );
        getWindow().setFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );

        // External storage cannot store executables with the executable bit set, these permissions can only result from locally stored files.
        // https://github.com/termux/termux-app/issues/252
        com.SetResourcesPath( getAssets(), getFilesDir().getAbsolutePath() );

        myView = new com.SurfaceView( this );
        this.setContentView( myView );

        _instance = this;

    }


Neither of the log tags are printed in the log. I can't figure out why this isn't actually being initialized.

I've tried changing the overridden function from "public void" to "protected void". I've also added the following code to the onResume function as I saw someone suggested in an answer to someone's similar problem:

if (myView == null) {
            myView = new SurfaceView(this);
            this.setContentView(myView);
        }
        myView.onResume();

        if (_instance == null) {
            _instance = this;
        }

So far none of these have worked. I've also tried using debug mode and I get stuck in what feels like a never ending loop. I know it's not a never ending loop because it happens before the blank screen shows up and I know that eventually the blank screen shows up. But I've stepped over this thread hundreds of times with no end in sight. So I'm hoping someone somewhere can find my mistake.

0

There are 0 best solutions below