[Android-development] Crash when calling Java method from C++

Thomas Lang thomas-lang at raven-worx.net
Thu Sep 1 22:36:18 CEST 2016


Hi,

i have a crash when using trying to call a java method from C++:

In my activity class i have:

public static void ShowToast( String text )
{
	class ToastRunnable implements Runnable
	{
		String msg;

		ToastRunnable(String m) { msg = m; }

		@Override
		public void run() {
				Toast.makeText(MyActivity.Instance.getApplicationContext(), msg,  
Toast.LENGTH_LONG).show();
		}
	}
	MyActivity.Instance.runOnUiThread( new ToastRunnable( text ) );
}

 From the C++ side i do simply this:

QAndroidJniObject::callStaticMethod<void>(
             "package/path/MyActivity",
             "ShowToast", "(Ljava/lang/String;)V",
             QAndroidJniObject::fromString( msg ).object<jstring>()
     );

The result is a abitrary crash, with no useable stacktrace and with no  
output in the console. The crash is somehow caused by the  
runOnUiThread call.
So i guess this is a variable lifetime issue?

I am testing on a Sony Xperia Z5 (Android 6)

thank you in advance.





More information about the Android-development mailing list