I am stuck at a strange problem, pretty strange!!
Problem : In the following project, a native method is called from android using JNI call. Whenever the native method returns, the android activity restarts (oncreate callback method is called again). I confirmed this using a log file inside the "oncreate()". It all results into a recursion!! why??
Please help :(
JAVA CODE
public class Brahma extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.brahma);
Log.v("Sumit","on create called");
TextView text=(TextView)findViewById(R.id.textView);
ImageView img=(ImageView)findViewById(R.id.imageView);
Mat inputFrame= new Mat();
String str =JNIMessage(inputFrame.getNativeObjAddr());
text.setText(str);
Bitmap bmp = Bitmap.createBitmap(inputFrame.cols(), inputFrame.rows(),
Bitmap.Config.ARGB_8888);
Utils.matToBitmap(inputFrame, bmp);
img.setImageBitmap(bmp);
}
public static native String JNIMessage(long l);
static
{
if (!OpenCVLoader.initDebug())
{
// Handle initialization error
} else
System.loadLibrary("brahma");
}
}
NATIVE CODE
using namespace std;
using namespace cv;
extern "C"
{
JNIEXPORT jstring JNICALL Java_com_example_brahma_Brahma_JNIMessage(JNIEnv* , jobject, jlong ;
JNIEXPORT jstring JNICALL Java_com_example_brahma_Brahma_JNIMessage(JNIEnv* env, jobject
thiz,jlong addr)
{
static int i=0;
char buffer[100];
sprintf(buffer, "native function called : time : %d", i++);
__android_log_print(ANDROID_LOG_INFO, "Sumit", buffer);
Mat& frame = *(Mat*)addr;
VideoCapture cap(0); // open the default camera
cap>>frame;
return env->NewStringUTF("Success");
}
}