So, maybe you can help me understand it better.
Is it Class or Object to “define” the class? I found both examples on the net :
//CLASS
AndroidJavaClass cls = new AndroidJavaClass("com.my.test.MainActivity");//class
AndroidJavaObject obj = cls.Call<AndroidJavaObject>("startFunc");
//OR OBJECT, the same?
AndroidJavaObject jo = new AndroidJavaObject("com.my.test.MainActivity");//object
AndroidJavaObject obj = cls.Call<AndroidJavaObject>("startFunc");
Then, with this example, the log returns nothing, whereas with the example in my first post (with CallStatic) the log returned something. So it makes me think I don’t know how to use JavaObject.
With the code above in Unity (with class or object), then with this in Eclipse, the ./adb logcat never shows this log :
//#1
public class MainActivity extends Activity {
public void startFunc(){
Log.i("------- ME -------", "--------------- ME ----------------");
Log.i("------- ME -------", "--------------- ME ----------------");
Log.i("------- ME -------", "--------------- ME ----------------");
Log.i("------- ME -------", "--------------- ME ----------------");
Log.i("------- ME -------", "--------------- ME ----------------");
Log.i("------- ME -------", "--------------- ME ----------------");
So there is no connection with “JavaObject”.
I also tried with a Singleton, I am not sure if this is what you wanted to tell me Vladimirg, but when I looked for some examples of a Singleton with an Activity, I found answers saying it should work with an extent of “Application” :
(Edit: I actually think this is wrong because the singleton is not MainActivity, but I don’t really know how to make MainActivity as the Singleton.)
//#2
//MAIN ACTIVITY
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Singleton
app = (MyApplication)getApplication();
MySingleton.getInstance().customSingletonMethod();
}
//APPLICATION
import android.app.Application;
public class MyApplication extends Application
{
@Override
public void onCreate()
{
super.onCreate();
initSingletons();
}
protected void initSingletons()
{
MySingleton.initInstance();
}
}
//#SINGLETON
public class MySingleton
{
private static MySingleton instance;
public static void initInstance()
{
if (instance == null){
instance = new MySingleton();
}
}
public static MySingleton getInstance()
{
return instance;
}
private MySingleton() { }
public void customSingletonMethod()
{
Log.i("------- ME -------", "------////--------- ME ----------------");
Log.i("------- ME -------", "-----////------- ME ----------------");
Log.i("------- ME -------", "-----////-------- ME ----------------");
Log.i("------- ME -------", "-----////-------- ME ----------------");
Log.i("------- ME -------", "------////------- ME ----------------");
}
}
This does not show anything in the Terminal.
Maybe you have an example that works with JavaObject ? (or a correct Singleton?)
@jvil: it seems extending this class could lead to issues with multiple plugin? If so, I should maybe try not to extend it, if by any chance I can make this work