gpt4 book ai didi

android - UnityPlayerActivity 没有收到 onCreate() 日志

转载 作者:太空宇宙 更新时间:2023-11-03 10:23:17 44 4
gpt4 key购买 nike

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

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() 不会在 Activity 开始时被调用。我的 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>

最佳答案

正如尼古拉斯所说,检查 list 确保这部分是正确的

<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>

关于android - UnityPlayerActivity 没有收到 onCreate() 日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16352502/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com