[英]JNI - Alert dialog on Android
我想在带有JNI的Android上显示简单的Alert对话框。 这是我的代码:
MyApp.cpp中:
QtAndroid::androidActivity().callMethod<void>("popupDialogMain", "()V");
主要活动:
public void popupDialogMain()
{
Log.d("Alert Dialog ", "33333333--------------------------");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
Log.d("Alert Dialog ", "44444--------------------------");
builder.setMessage("Look at this dialog!")
.setCancelable(true)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do things
}
});
AlertDialog alert = builder.create();
alert.show();
}
每当我想使用它时,我的应用程序就会崩溃,这是日志:
D/Alert Dialog (28644): 33333333--------------------------
D/Alert Dialog (28644): 44444--------------------------
F/art (28644): art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION:id
F/art (28644): art/runtime/check_jni.cc:65] in call to NewGlobalRef
F/art (28644): art/runtime/check_jni.cc:65] "QtThread" prio=10 tid=11 Runnable
F/art (28644): art/runtime/check_jni.cc:65] | group="main" sCount=0 dsCount=0 obj=0x12c4e440 self=0xa1433400
F/art (28644): art/runtime/check_jni.cc:65] | sysTid=28825 nice=-11 cgrp=apps sched=0/0 handle=0xaef7ec00
F/art (28644): art/runtime/check_jni.cc:65] | state=R schedstat=( 1790287538 286358026 2178 ) utm=151 stm=28 core=0 HZ=100
F/art (28644): art/runtime/check_jni.cc:65] | stack=0xaed4c000-0xaed4e000 stackSize=1012KB
F/art (28644): art/runtime/check_jni.cc:65] | held mutexes= "mutator lock"(shared held)
F/art (28644): art/runtime/check_jni.cc:65] native: #00 pc 00004640 /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
有什么解决的建议吗?
用这个:
public void popupDialogMain()
{
Log.d("Alert Dialog ", "33333333--------------------------");
final Context context = getApplicationContext();
Handler h1 = new Handler(context.getMainLooper());
h1.post(new Runnable() {
@Override
public void run() {
popupDialogMain1();
}
});
}
public void popupDialogMain1()
{
Log.d("Alert Dialog ", "44444--------------------------");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
Log.d("Alert Dialog ", "5555--------------------------");
builder.setMessage("Look at this dialog!")
.setCancelable(true)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do things
}
});
AlertDialog alert = builder.create();
alert.show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.