昨天我们的一位客户报告说我们的应用程序在他的Xperia Z1上安装了Android 4.4.2。在avd中进行测试后,我们发现,API 18或更早版本不会发生此异常。返回对话框后应用程序崩溃,但原因似乎是AlertDialog.setView
,因为如果我们删除此行,则应用程序不会崩溃。
我已经花了很长时间在网上搜索解决方案并尝试不同的方法,但没有找到任何有助于我的方法。
API 19和AlertDialog.setView
是否存在任何已知问题?我们做错了吗?有人知道如何解决这个问题吗?
提前致谢
德克
这是我正在创建对话框的(简化但仍然崩溃)代码:
AlertDialog alert = null;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false).setPositiveButton("OK",
new DialogInterface.OnClickListener()
{
...
});
builder.setNeutralButton(
getResources().getString(R.string.text_button_help),
new DialogInterface.OnClickListener()
{
...
});
builder.setView(this.getLayoutInflater().inflate(R.layout.timeline,
null));
alert = builder.create();
return alert;
LogCat输出:
06-11 06:44:25.710: E/ViewRootImpl(1188): Attempting to destroy the window while drawing!
06-11 06:44:25.710: E/ViewRootImpl(1188): window=android.view.ViewRootImpl@b237f958, title=foo/bar
06-11 06:44:25.820: W/dalvikvm(1188): threadid=1: thread exiting with uncaught exception (group=0xb1a3aba8)
06-11 06:44:25.840: E/AndroidRuntime(1188): FATAL EXCEPTION: main
06-11 06:44:25.840: E/AndroidRuntime(1188): Process: foo, PID: 1188
06-11 06:44:25.840: E/AndroidRuntime(1188): java.lang.IllegalStateException: Surface has already been released.
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Surface.checkNotReleasedLocked(Surface.java:408)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Surface.unlockCanvasAndPost(Surface.java:261)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2507)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2409)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2253)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1883)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Choreographer.doFrame(Choreographer.java:544)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.os.Handler.handleCallback(Handler.java:733)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.os.Handler.dispatchMessage(Handler.java:95)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.os.Looper.loop(Looper.java:136)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-11 06:44:25.840: E/AndroidRuntime(1188): at java.lang.reflect.Method.invokeNative(Native Method)
06-11 06:44:25.840: E/AndroidRuntime(1188): at java.lang.reflect.Method.invoke(Method.java:515)
06-11 06:44:25.840: E/AndroidRuntime(1188): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-11 06:44:25.840: E/AndroidRuntime(1188): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-11 06:44:25.840: E/AndroidRuntime(1188): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
我们最终自己想出来了,至少我们是如何让它发挥作用的。问题是我们仍在使用弃用的showDialog()
- 方法而不是DialogFragments
。似乎有些情况showDialog()
和AlertDialog.setView()
不能一起工作,在其他情况下他们显然会这样做,我们还有另一个对话框仍在工作。将DialogFragments
引入我们的应用后,对话框就像以前的API版本一样启动。