Hi, I am trying to extend UnityPlayerActivity with the help of docs.unity3d. I have a simple jar file with MainActivity class and also included the file classes.jar to the libs folder.
My class file has following code.
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);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public static void callMe()
{
Log.i("Hiren","==============Function CALLED==============");
}
}
I can call the static function callMe () through my c# script but my onCreate() is not called at the start of the activity. My C# script is
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");
}
}
When I call “CallMe” method, I get log of being called. but I didnt get any log from onCreate(). My AndroidManifest.xml is also fine I guess. It has activity of the class
<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>
Is there any problem in my code?
ok.. Let me try this.. If it works.. then this should be an awesome answer..
– hirenkachayes, sure.
– abdulbasit.abdi