UnityPlayerActivity没有获得onCreate()日志

时间:2013-05-03 05:54:02

标签: android java-native-interface unity3d

我试图在docs.unity3d的帮助下扩展UnityPlayerActivity。我有一个带有MainActivity类的简单jar文件,还包含libs文件夹中的classes.jar文件。我的类文件有以下代码。

package com.example.testactivity;

import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import com.unity3d.player.UnityPlayerActivity;

public class MainActivity extends UnityPlayerActivity
{

@Override
public void onCreate(Bundle savedInstanceState) {
  Log.i("Hiren","==============ON CREATE CALLED==============");
  super.onCreate(savedInstanceState);
}


public static void callMe()
{
   Log.i("Hiren","==============Function CALLED==============");
}
}

我可以通过我的c#脚本调用静态函数callMe(),但是在活动开始时不调用onCreate()。我的C#脚本是

private static FBShare _instance;

public static FBShare Instance
{
get
{
  if(_instance == null)
     _instance = new FBShare();
  return _instance;
}
}

private AndroidJavaClass cls_Fb = new AndroidJavaClass("com.example.testactivity.MainActivity");

public void CallMe()
{

  using(AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  {

    using(AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
    {
      cls_Fb.CallStatic("callMe");
    }
  }

当我调用“CallMe”方法时,我会得到被调用的日志。但我没有从onCreate()获得任何日志。

AndroidMenifest.xml文件包含

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.testactivity.MainActivity"
    android:installLocation="preferExternal"
    android:versionCode="1"
    android:versionName="1.0">
    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"
        android:anyDensity="true"/>

    <application

        android:label="@string/app_name"
        android:debuggable="true">
        <activity android:name="com.unity3d.player.UnityPlayerProxyActivity"
                  android:label="@string/app_name"
                  android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:label="@string/app_name"
                  android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
        </activity>
        <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
                  android:label="@string/app_name"
                  android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            <meta-data android:name="android.app.lib_name" android:value="unity" />
            <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
        </activity>
        <activity android:name="com.unity3d.player.VideoPlayer"
                  android:label="@string/app_name"
                  android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
        </activity>
        <activity android:name=".MainActivity"  
                  android:label="@string/app_name"
                  android:configChanges="keyboardHidden|orientation" >
              <meta-data android:name="android.app.lib_name" android:value="unity" />
                <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
        </activity>
        <uses-library android:name="com.google.android.maps" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_INTERNET" />

    </application>
</manifest>

1 个答案:

答案 0 :(得分:2)

尼古拉斯说,检查清单 确保此部分正确

<activity
    android:name=".MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>