【问题标题】:android.view.WindowLeaked after Camera Intent相机意图后的android.view.WindowLeaked
【发布时间】:2018-02-20 21:21:32
【问题描述】:

我正在通过 Eclipse 开发一个 Android APP,但在查找导致以下错误的原因时遇到了一些麻烦:

我正在调用一个 ACTION_IMAGE_CAPTURE Intent 来打开相机并期待一个 Image on 结果。所以:

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 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 到我正在调试的设备的调试连接在相机活动内终止。当我确认拍摄的照片时,它会崩溃。

【问题讨论】:

  • DB.java 的第 39 行是什么?
  • 这是一个 throw new RuntimeException() 在 Catch 内的尝试,仅在初始化时调用以设置数据库连接。我确实在上面放了一个断点,但在尝试时,它并没有就此停止。
  • 您能否发布 DB.java 文件并指出第 39 行导致异常的位置?
  • iRuth。我已经编辑了这个主题,因为当我实例化一个活动的成员时,你注意到的那个异常就被抛出了。我将调用移至 onCreate,现在 Exception 和 Place 发生了变化。但同样的行为。

标签: java android runtimeexception


【解决方案1】:

删除此行并尝试一次...

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

这是由于 uri 泄漏异常...最好不要将 uri 传递给获取文件的意图

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多