Saturday, April 12, 2014

C + + non-static function calls android


This is the code under
xcode# If (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
JniMethodInfo minfo;
bool isHave = JniHelper :: getStaticMethodInfo (minfo, "org / com / TestFirst / ProcessManager", "getInstance", "() Ljava / lang / Object;");
CCLog ("start calling!");
jobject jobj = NULL;
if (isHave)
{
jobj = minfo.env-> CallStaticObjectMethod (minfo.classID, minfo.methodID);
}
CCLog ("get jobj");
isHave = JniHelper :: getMethodInfo (minfo, "org / com / TestFirst / ProcessManager", "getProcess", "() V");
CCLog ("process!");
std :: cout << isHave << std :: endl;
if (isHave)
{
CCLog ("Receive!");
minfo.env-> CallVoidMethod (jobj, minfo.methodID);
CCLog ("completed!");
}
else
{
CCLog ("jni-java function is finished");
}
# Endif

-------------------------------------------------- --------------
Here is the java code
eclipse underpackage org.com.TestFirst;

import org.cocos2dx.lib.Cocos2dxActivity;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

public class ProcessManager extends Cocos2dxActivity {
private static String TAG = "AM_MEMORYIPROCESS";
private ActivityManager mActivityManager = null;
public static ProcessManager actInstance = null ;/ / define a single case
public static Object getInstance () {
if (actInstance == null)
{
actInstance = new ProcessManager ();
}
Log.d ("daa", "fsfsdf");
return actInstance;
}
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
}
public void getProcess ()
{
Log.d ("cocosAct", "go on!!!");
}
}
After the execution, which can be seen in LogCat under xcode play log, but the implementation of the minfo.env-> CallVoidMethod (jobj, minfo.methodID), and then collapse.
getProcess () in the log does not print out, this method is called non-static function find online, so we are writing, I do not know what went wrong, ask for help to solve the heroes.
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
If you are calling in another thread, please check if there is (g_jvmInstance) -> AttachCurrentThread (& env, NULL);
Reply:
cited a floor luowenlong860502 reply:
if it is called in another thread, please check if there is (g_jvmInstance) -> AttachCurrentThread (& env, NULL );

In the beginning I did not let ProcessManager class inherits Activity class, so call a non-static functions can not be wrong, but after inheriting Activity on the wrong class.
Reply:
reference to the second floor u012240007 reply:
Quote: references to a floor luowenlong860502 reply:

If you are calling in another thread, please check if there is (g_jvmInstance) -> AttachCurrentThread (& env, NULL);

In the beginning I did not let ProcessManager class inherits Activity class, so call a non-static functions can not be wrong, but later on the Activity class inherits wrong.


No wonder ah, Activity is running on the UI thread, how can you call it a member of the method in other places too? Activity itself can only be invoked
Reply:
reference to the third floor luowenlong860502 reply:
Quote: references to the second floor u012240007 reply:

Quote: references to a floor luowenlong860502 reply:

If you are calling in another thread, please check if there is (g_jvmInstance) -> AttachCurrentThread (& env, NULL);

In the beginning I did not let ProcessManager class inherits Activity class, so call a non-static functions can not be wrong, but later on the Activity class inherits wrong.


No wonder ah, Activity is running on the UI thread, how can you call it a member of the method in other places too? Activity itself can only be invoked

When I wrote the above return actInstance object, ah! Not directly call the member function inside ProcessManager.
You look at the code I posted above should be how to change it?
android I really do not understand, but now there is a project where things need to use Android, and then want to measure what is called, is stuck.

No comments:

Post a Comment