问题"已泄漏窗QUOT;在对话 [英] Problem with "has leaked window" on dialog

查看:130
本文介绍了问题"已泄漏窗QUOT;在对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个Android应用程序给用户打电话基于他试图拨打该号码不同的替代数量的选项。
要做到这一点我有被称为广播接收器,获取的数量,检查是否有替代品,然后显示对话框启动一个新的活动来做到这一点,因为它不能对自己做的。
一切都只是活动确定出现的对话框之前关闭掉,所以我得到一个窗口泄露的例外,但我不知道怎样才能让它工作,等待对话的结果(注释在NumberDialog类环路)的结果也不例外,但没有对话框。

来源是:

 包com.frisco.hello;进口java.io.IOException异常;
进口的java.util.ArrayList;
进口的java.util.List;进口android.app.AlertDialog;
进口android.content.BroadcastReceiver;
进口android.content.Context;
进口android.content.DialogInterface;
进口android.content.Intent;
进口android.database.SQLException;
进口android.net.Uri;
进口android.util.Log;
进口android.widget.Toast;进口com.frisco.hello.util.DataBaseHelper;公共类来电扩展广播接收器{    私有静态最后弦乐TAG =HelloWorld的;    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
        串intentAction = intent.getAction();
        串号= getResultData();        如果(intentAction.equals(Intent.ACTION_NEW_OUTGOING_CALL)及&放大器;数!= NULL)
        {
            Log.d(TAGRecibido evento POR EL NUMERO+号);
            DataBaseHelper myDbHelper =新DataBaseHelper(背景);
            尝试{
                myDbHelper.createDataBase();
            }赶上(IOException异常IOE){
                抛出新的错误(无法创建数据库);
            }
            尝试{
                myDbHelper.openDataBase();
            }赶上(的SQLException SQLE){
                扔SQLE;
            }
            的String [] =结果myDbHelper.getAlternateNumbers(号);
            如果(results.length→1){                意图=新意图(Intent.ACTION_CALL,
                        Uri.fromParts(com.frisco.hello.number,Uri.de code(数字),NULL));
                数=无效;
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(意向);
            }
        }
    }}

号码对话框:

 包com.frisco.hello;进口java.io.IOException异常;进口android.app.Activity;
进口android.app.AlertDialog;
进口android.content.DialogInterface;
进口android.content.DialogInterface.OnCancelListener;
进口android.database.SQLException;
进口android.net.Uri;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.Window;进口com.frisco.hello.util.DataBaseHelper;公共类NumberDialog延伸活动{
    私有静态最后弦乐TAG =HelloWorld的;
    私人的CharSequence []交替;
    私人CharSequence的选择= NULL;    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);        。URI URI = getIntent()的getData();
        目标字符串= uri.getSchemeSpecificPart();
        Log.d(TAGDecodificado EL NUMERO科莫+目标);
        DataBaseHelper myDbHelper =新DataBaseHelper(本);
        尝试{
            myDbHelper.createDataBase();
        }赶上(IOException异常IOE){
            抛出新的错误(无法创建数据库);
        }
        尝试{
            myDbHelper.openDataBase();
        }赶上(的SQLException SQLE){
            扔SQLE;
        }
        的String [] =结果myDbHelper.getAlternateNumbers(目标);
        候补=结果;
        新AlertDialog.Builder(本)
            .setTitle(选择号码)
            .setItems(成果,新DialogSelectionClickHandler())
            .setNegativeButton(取消,新DialogInterface.OnClickListener(){
                    公共无效的onClick(DialogInterface对话,诠释whichButton){
                        完();
                    }
                })
            .setOnCancelListener(新OnCancelListener(){
                公共无效onCancel(DialogInterface对话){
                    完();
                }
            })
            。显示();
/ *而(选择== NULL){
            尝试{
                视频下载(500);
            }赶上(InterruptedException的E){
                ;
            }
        }
        Log.i(TAGSeleccionado+选择);
* /
    }    公共类DialogSelectionClickHandler实现DialogInterface.OnClickListener,DialogInterface.OnDismissListener
    {        @覆盖
        公共无效的onClick(DialogInterface对话,诠释它){
            Log.i(TAG,其中+_+交替[它]);
            选择=交替[这]
        }        @覆盖
        公共无效onDismiss(DialogInterface对话){
            Log.i(TAG驳回);
            选定=候补[0];
        }
    }
}

LogCat中

  09-29 17:52:28.309:ERROR /窗口管理器(4464):活动com.frisco.hello.NumberDialog渗漏窗口com.android.internal.policy.impl.PhoneWindow $ @ DecorView这43e48270最初加入这里
09-29 17:52:28.309:ERROR /窗口管理器(4464):android.view.WindowLeaked:活动com.frisco.hello.NumberDialog渗漏窗口com.android.internal.policy.impl.PhoneWindow$DecorView@43e48270这是原本在这里添加
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.view.ViewRoot<&初始化GT;(ViewRoot.java:247)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.view.Window $ LocalWindowManager.addView(Window.java:424)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.app.Dialog.show(Dialog.java:241)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.app.AlertDialog $ Builder.show(AlertDialog.java:802)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在com.frisco.hello.NumberDialog.onCreate(NumberDialog.java:56)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.os.Handler.dispatchMessage(Handler.java:99)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.os.Looper.loop(Looper.java:123)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在android.app.ActivityThread.main(ActivityThread.java:4627)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在java.lang.reflect.Method.invokeNative(本机方法)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在java.lang.reflect.Method.invoke(Method.java:521)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-29 17:52:28.309:ERROR /窗口管理器(4464):在dalvik.system.NativeStart.main(本机方法)


解决方案

看来我无法激活其他活动同时在打电话的过程。
但是,这是不是我是想,停止显示一个对话框,当前呼叫,然后开始一个新的不同的数字。
所以,解决办法是为在主叫方类改变为简单:
数= NULL;
对于
setResultData(NULL);
这的确结束通话,并让我的新的活动,以显示其对话框。

I am writing an android app to give the user the option to call a different alternative number based on the number he tried to call. To do that I have BroadCastReceiver that gets the number being called, checks if there are alternatives and then to show the dialog it starts a new activity to do that as it can not do on its own. Everything is ok except the activity get closed before the dialog appears, so I get a window leaked exception but I can not see how I can make it works, waiting for the result of the dialog (uncomment the loop in the NumberDialog class) results in no exception but no dialog.

The sources are:

package com.frisco.hello;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.SQLException;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;

import com.frisco.hello.util.DataBaseHelper;

public class Caller extends BroadcastReceiver {

    private static final String TAG = "HelloWorld";

    @Override
    public void onReceive(Context context, Intent intent) {
        String intentAction = intent.getAction();
        String number = getResultData();

        if (intentAction.equals(Intent.ACTION_NEW_OUTGOING_CALL) && number != null)
        {
            Log.d(TAG, "Recibido evento por el numero" + number);
            DataBaseHelper myDbHelper = new DataBaseHelper(context);         
            try {            
                myDbHelper.createDataBase();             
            } catch (IOException ioe) {          
                throw new Error("Unable to create database");            
            }            
            try {            
                myDbHelper.openDataBase();           
            }catch(SQLException sqle){           
                throw sqle;          
            }
            String[] results = myDbHelper.getAlternateNumbers(number);
            if (results.length > 1) {

                intent = new Intent(Intent.ACTION_CALL,
                        Uri.fromParts("com.frisco.hello.number", Uri.decode(number),null));
                number = null;
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);  
            }
        }
    }   

}

Number dialog:

package com.frisco.hello;

import java.io.IOException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.database.SQLException;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

import com.frisco.hello.util.DataBaseHelper;

public class NumberDialog extends Activity {
    private static final String TAG = "HelloWorld"; 
    private CharSequence[] alternates;
    private CharSequence selected = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        Uri uri = getIntent().getData();
        String target = uri.getSchemeSpecificPart();
        Log.d(TAG,"Decodificado el numero como "+target);
        DataBaseHelper myDbHelper = new DataBaseHelper(this);        
        try {            
            myDbHelper.createDataBase();             
        } catch (IOException ioe) {          
            throw new Error("Unable to create database");            
        }            
        try {            
            myDbHelper.openDataBase();           
        }catch(SQLException sqle){           
            throw sqle;          
        }  
        String[] results = myDbHelper.getAlternateNumbers(target);
        alternates = results;
        new AlertDialog.Builder( this)
            .setTitle( "Select number" )
            .setItems( results, new DialogSelectionClickHandler())
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        finish();
                    }
                })
            .setOnCancelListener(new OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    finish();
                }
            })          
            .show(); 
/*      while (selected == null) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                ;
            }
        }
        Log.i( TAG, "Seleccionado " + selected );
*/      
    }

    public class DialogSelectionClickHandler implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener
    {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Log.i( TAG, which+"_"+alternates[which] );
            selected = alternates[which];
        }

        @Override
        public void onDismiss(DialogInterface dialog) {
            Log.i( TAG, "Dismissed" );
            selected = alternates[0];
        }
    }    
}

LogCat

09-29 17:52:28.309: ERROR/WindowManager(4464): Activity com.frisco.hello.NumberDialog has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e48270 that was originally added here
09-29 17:52:28.309: ERROR/WindowManager(4464): android.view.WindowLeaked: Activity com.frisco.hello.NumberDialog has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e48270 that was originally added here
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.view.ViewRoot.<init>(ViewRoot.java:247)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.Dialog.show(Dialog.java:241)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at com.frisco.hello.NumberDialog.onCreate(NumberDialog.java:56)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.os.Looper.loop(Looper.java:123)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at java.lang.reflect.Method.invokeNative(Native Method)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at java.lang.reflect.Method.invoke(Method.java:521)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at dalvik.system.NativeStart.main(Native Method)

解决方案

It seems that I can not activate other Activity while in the phone call process. But that was not what I was trying, stopping the current call showing a dialog and then starting a new one with different number. So the fix is as simple as changing on the Caller class: number = null; for setResultData(null); which indeed ends the calls and allow my new activity to show its dialog.

这篇关于问题&QUOT;已泄漏窗QUOT;在对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆