【发布时间】:2013-04-01 12:58:36
【问题描述】:
我们正在为安卓开发一款独立游戏,并希望用户选择他的昵称。我们选择使用 NDK 提供的 Native Activity,因为这似乎是最简单的方法。
我们遇到的第一个键盘问题是函数 ANativeActivity_showSoftInput() 似乎什么都不做(如 here 所描述的那样),所以我们使用 JNI 调用函数来调出键盘:
static void showKeyboard(Activity activity) {
String s = Context.INPUT_METHOD_SERVICE;
InputMethodManager m = (InputMethodManager)activity.getSystemService(s);
View w = activity.getWindow().getDecorView();
m.showSoftInput(w, 0);
}
这可以很好地调出键盘,并且可以在某些设备上一起正常工作。但在其他设备(例如 Nexus 7)上,当用户尝试通过点击“隐藏键盘”按钮关闭键盘时,应用程序会冻结并显示以下调试输出:
I/InputDispatcher( 453): Application is not responding: AppWindowToken{429b54a8 token=Token{42661288 ActivityRecord{41bb0b00 u0 com.example.project/android.app.NativeActivity}}} - Window{420d6138 u0 com.example.project/android.app.NativeActivity}. It has been 5006.7ms since event, 5005.6ms since wait started. Reason: Waiting because the focused window has not finished processing the input events that were previously delivered to it.
I/WindowManager( 453): Input event dispatching timed out sending to com.example.project/android.app.NativeActivity
然后用户会看到一个对话框:
Project isn't responding. Do you want to close it? [Wait]/[OK]
我们做错了什么吗?或者这可能是一个错误? this one 之类的问题似乎表明键盘功能从未在本机胶水中正确实现。
附带说明,我们尚未在许多设备上进行测试,但不会崩溃的设备是具有较旧 Android 操作系统的设备。此外,在确实崩溃的地方,当键盘出现时,它会将 back 按钮从一个看起来像这样的 更改为一个看起来像这样的按钮 。也许这对应于他们第一次开发本机胶水时没有考虑的不同输入事件?我只是猜测。
无论如何,如果有人在使用本机活动时软键盘工作,请告诉我们你是如何做到的。
干杯
更新
它已被报告为 Android here 中的一个错误,但我们仍然很乐意听到解决方法。如果您也受到它的影响,您可能想对该问题进行投票(按星号)。
【问题讨论】:
标签: android android-layout android-ndk native-activity