English 中文(简体)
无法减轻我非静态功能的机器人JNIClass
原标题:AndroidJNIClass unable to excute my non-static function

i have calling java function from my unity code. I have both static & non-static type of functions in my java class To access first static function, i used:

AndroidJavaClass plugin = new AndroidJavaClass("com.android.test.TestActivity");
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");        
plugin.CallStatic("InstantiateMe", qwe);

上面的代码运行正常, 但在此之后, 当 Im 试图执行我的非静态函数时, 它没有实际执行。 甚至没有给予任何例外或错误 。

<强 > 我调用非静态函数的代码

AndroidJavaClass plugin = new AndroidJavaClass("com.android.test.TestActivity");
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");        
plugin.Call("Enable", qwe);

帮我个忙 我困在这里了

最佳回答

use your "activity" variable for non-static calls: activity.Call("Enable", qwe); There is example of static and non-static functions calls:

public class Caller {
  private readonly AndroidJavaClass _ActivityClass;
  private readonly AndroidJavaObject _ActivityObject;
  private readonly AndroidJavaClass _MyActivityClass; 

  public Caller() {
    _ActivityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    _MyActivityClass = new AndroidJavaClass("com.example.u2aTest.MyMainActivity"); 

    _ActivityObject = _ActivityClass.GetStatic("currentActivity");
    // AndroidJavaObject my_activity_object = _MyActivityClass.GetStatic("currentActivity"); //doesn t work
  }

  public void MakeTestCalls() {
    _ActivityObject.Call("testVoid"); // works fine
    //_ActivityClass.CallStatic("testVoidStatic"); // doesn t works
   _MyActivityClass.CallStatic("testVoidStatic"); // works fine
    //_ActivityObject.CallStatic("testVoid"); // doesn t work on some divices

   //public int testInt(int intValue)
   int iresult = _ActivityObject.Call<int>("testInt", 999);

   //public String testStringString(String paramValue)
   String sresult = _ActivityObject.Call<String>("testStringString", "s2");      

   //public static int testIntStatic(int intValue) 
   iresult = _MyActivityClass.CallStatic<int>("testIntStatic", 999);

   //public static String testStringStringStatic(String paramValue)
   sresult =_MyActivityClass.CallStatic<String>("testStringStringStatic", "s1");
  }
}

查看",http://code.google.com/p/dvsrc/downloads/detail?name=2012113_Unity2AndroidTest.7z" rel=“noreferr”>

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签