gpt4 book ai didi

java - android.view.WindowLeaked 后 Camera Intent

转载 作者:行者123 更新时间:2023-11-30 02:21:25 35 4
gpt4 key购买 nike

我正在通过 Eclipse 开发一个 Android 应用程序,我在查找导致以下错误的原因时遇到了一些问题:

我正在调用一个 ACTION_IMAGE_CAPTURE Intent 来打开相机,并期望在结果上显示图像。所以:

Intent v_Intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try
{
v_Intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(createImageFile()));
}
catch (IOException e)
{
Builder v_Builder = new AlertDialog.Builder(GroupPageActivity.this);
v_Builder.setIcon(android.R.drawable.ic_dialog_alert);
v_Builder.setTitle("Arquivo não Anexado");
v_Builder.setMessage(R.string.cameraSaveErrorInfo).setNegativeButton("OK", null).show();
e.printStackTrace();
return;
}
v_Intent.putExtra("return-data", true);
GroupPageActivity.this.startActivityForResult(v_Intent, IMAGE_CAMERA_REQUEST_ATTACHMENT_CODE);

在这里期待它:

protected void onActivityResult(int p_Code, int p_Result, Intent p_Intent)
{
if (p_Result != RESULT_CANCELED)
{
switch (p_Code)
{
...
case IMAGE_CAMERA_REQUEST_ATTACHMENT_CODE:
{
if (p_Intent != null)
{
Uri capturedImageUri = p_Intent.getData();
//capturedImageUri = g_ImageUri;
if (capturedImageUri != null)
{
m_ImageUriList.add(capturedImageUri);
new CallAddThumbnails().execute();
}
else {
Builder v_Builder = new AlertDialog.Builder(GroupPageActivity.this);
v_Builder.setIcon(android.R.drawable.ic_dialog_alert);
v_Builder.setTitle("Arquivo não Anexado");
v_Builder.setMessage(R.string.cameraImageErrorInfo).setNegativeButton("OK", null).show();
}
}
else
{
Uri capturedImageUri = Uri.parse(g_CurrentPhotoPath);
m_ImageUriList.add(capturedImageUri);
new CallAddThumbnails().execute();
}
break;
}
}
}
}

我能够启动相机 Activity ,拍摄照片,但是,有时,并非总是,我得到这个:

Activity MyApp.GroupPageActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40583060 that was originally added here
android.view.WindowLeaked: Activity MyApp.GroupPageActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40583060 that was originally added here
at android.view.ViewRoot.<init>(ViewRoot.java:294)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:184)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:127)
at android.view.Window$LocalWindowManager.addView(Window.java:455)
at android.app.Dialog.show(Dialog.java:272)
at MyApp.GroupPageActivity$CallAddThumbnails.onPreExecute(GroupPageActivity.java:628)
at android.os.AsyncTask.execute(AsyncTask.java:422)
at MyApp.GroupPageActivity.onActivityResult(GroupPageActivity.java:416)
at android.app.Activity.dispatchActivityResult(Activity.java:3975)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2628)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2207)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2235)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1768)
at android.app.ActivityThread.access$1500(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:999)
at android.os.Handler.dispatchMessage(Handler.java:130)
at android.os.Looper.loop(SourceFile:351)
at android.app.ActivityThread.main(ActivityThread.java:3820)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:538)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
at dalvik.system.NativeStart.main(Native Method)

调用在此 GroupPageActivity 上。而且我确信,当它发生时,它会在调用 onActivityResult 之前崩溃。

有什么想法吗?

PS.: 我在这里抛出另一个异常:

Private Phone m_UserPhone = ConfigurationController.GetActiveNotNull();

这是 GroupPageActivity 的成员。

PS2.:我注意到,当我拍照时,从 Eclipse 到我正在调试的设备的调试连接在相机 Activity 中终止了。当我确认拍摄的照片时,它崩溃了。

最佳答案

去掉这一行再试一次...

v_Intent.putExtra(MediaStore.EXTRA_OUTPUT,   Uri.fromFile(createImageFile()));

发生这种情况是因为 uri 泄漏异常...最好不要将 uri 传递给获取文件的 Intent

关于java - android.view.WindowLeaked 后 Camera Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28501971/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com