我正在使用 getApplicationContext() 函数创建一个对话框,当我调用 dialog.show() 时,这会导致程序崩溃。我正在使用 getApplicationContext() 因为我试图在 Camera.PictureCallback() 中打开对话框,如下所示:
Camera.PictureCallback pictureCallbackJpeg = new Camera.PictureCallback()
{
public void onPictureTaken(byte[] data, Camera c)
{
Context context = getApplicationContext();
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.send_dialog);
dialog.setTitle("Send image?");
dialog.show();
camera.startPreview();
}
};
这是崩溃日志:
Thread [<1> main] (Suspended (exception WindowManager$BadTokenException))
Dialog.show() line: 245
myApp$1.onPictureTaken(byte[], Camera) line: 31
Camera$EventHandler.handleMessage(Message) line: 328
Camera$EventHandler(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 143
ActivityThread.main(String[]) line: 4914
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line: not available [native method]
任何想法如何解决这一问题?