活动渗漏窗口 [英] Activity has leaked window

查看:100
本文介绍了活动渗漏窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的启动画面,我做它,以便它检测到WiFi或3G是否启用。如果不是,一个对话框,屏幕提示用户退出并打开任何一个上。如果是,那么在code将继续。我不断收到一个错误在我的logcat中关于有一份被泄露的窗口我的活动。我不知道如何解决这个问题。 code和下面的logcat。任何想法?

下面是我的code:

  //创建一个WiFi和3G警告对话框
connectionDialog =新AlertDialog.Builder(SplashMain.this).create();
Log.d(TAG,对话创造了);
connectionDialog.setTitle(WiFi或3G没有检测请启用无论是WiFi或3G。);
connectionDialog.setButton(退出,新DialogInterface.OnClickListener(){
    @覆盖
    公共无效的onClick(DialogInterface对话,诠释它){
            完();
    }
});

wifiHandler =新的处理程序();
的setContentView(R.layout.splashscreen); //首先使开机画面加载
螺纹splashScreenTimer =新的Thread(){//创建一个定时器启动画面
    公共无效的run(){//创建一个运行类
        活套prepare()。 // prepare尺蠖
        尝试{//运行类中的方法
            INT screenTimer = 0;
            //使其最后3秒 - 创建一个while循环
            而(screenTimer< 3000){
                睡眠(100);的第二// 100 = 1 /第十
                screenTimer = screenTimer +100;
            }
            connectionState(); //检查wifi的东西
            Log.d(TAG,检查无线网络状态);
            如果(移动==真|| wifi的==真){
                Log.d(TAG,WiFi是真正的);
                connectionDialog.dismiss();
                startActivity(新的意向书(ravebox.dev.sdr.CLEARSCREEN));
                完();
                Log.d(TAG,启动活动);
            }
            如果(移动==虚假|| wifi的== FALSE){
                Log.d(TAG,WiFi是假的);
                wifiHandler.post(新的Runnable(){
                    @覆盖
                    公共无效的run(){
                        Log.d(TAG,显示对话框);
                        connectionDialog.show();
                        Log.d(TAG,show'd对话);
                    }
                });
            } //添加活动清单
        }赶上(InterruptedException异常E){
            e.printStackTrace();
        }最后{
            //完();
        }
    }
};
splashScreenTimer.start();
 

登录猫:

  08-30 22:45:32.188:ERROR /窗口管理器(334):活动ravebox.dev.sdr.SplashMain渗漏窗口com.android.internal.policy.impl.PhoneWindow $ DecorView @ 405377e0最初此处添加
08-30 22:45:32.188:ERROR /窗口管理器(334):android.view.WindowLeaked:活动ravebox.dev.sdr.SplashMain渗漏窗口com.android.internal.policy.impl.PhoneWindow$DecorView@405377e0这是原本在这里添加
08-30 22:45:32.188:ERROR /窗口管理器(334):在android.view.ViewRoot< INIT>(ViewRoot.java:258)
08-30 22:45:32.188:ERROR /窗口管理器(334):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-30 22:45:32.188:ERROR /窗口管理器(334):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-30 22:45:32.188:ERROR /窗口管理器(334):在android.view.Window $ LocalWindowManager.addView(Window.java:465)
08-30 22:45:32.188:ERROR /窗口管理器(334):在android.app.Dialog.show(Dialog.java:241)
08-30 22:45:32.188:ERROR /窗口管理器(334):在ravebox.dev.sdr.SplashMain $ 2 $ 1.运行(SplashMain.java:90)
08-30 22:45:32.188:ERROR /窗口管理器(334):在android.os.Handler.handleCallback(Handler.java:587)
08-30 22:45:32.188:ERROR /窗口管理器(334):在android.os.Handler.dispatchMessage(Handler.java:92)
08-30 22:45:32.188:ERROR /窗口管理器(334):在android.os.Looper.loop(Looper.java:123)
08-30 22:45:32.188:ERROR /窗口管理器(334):在android.app.ActivityThread.main(ActivityThread.java:3835)
08-30 22:45:32.188:ERROR /窗口管理器(334):在java.lang.reflect.Method.invokeNative(本机方法)
08-30 22:45:32.188:ERROR /窗口管理器(334):在java.lang.reflect.Method.invoke(Method.java:507)
08-30 22:45:32.188:ERROR /窗口管理器(334):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:841)
08-30 22:45:32.188:ERROR /窗口管理器(334):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-30 22:45:32.188:ERROR /窗口管理器(334):在dalvik.system.NativeStart.main(本机方法)
 

解决方案

下面是一个答案说明了为什么出现此问题:<一href="http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added">Activity有最初加入泄露的窗口

现在,在你万一你写了这个code

 如果(移动==真|| wifi的==真){
      Log.d(TAG,WiFi是真正的);
      connectionDialog.dismiss();
      startActivity(新的意向书(ravebox.dev.sdr.CLEARSCREEN));
      完();
      Log.d(TAG,启动活动);
}
 

在上面的code你在哪里展示 connectionDialog.dismiss(); 解雇之前

而在这code你是显示由 connectionDialog.show(对话); 但如果是code将其关闭。

 如果(移动==虚假|| wifi的== FALSE){
      Log.d(TAG,WiFi是假的);
      wifiHandler.post(新的Runnable(){
      @覆盖
      公共无效的run(){
         Log.d(TAG,显示对话框);
         connectionDialog.show();
         Log.d(TAG,show'd对话);
      }
});
 

所以,请找到一个解决方案,它应该是这样的。

显示在对话框中才刚刚开始,如果WiFi连接取消()并移动到下一个活动,如果没有连接取消()经过一段时间,并给予了WIFI找不到或连接的信息吧。

In my splash screen, I made it so that it detects whether wifi or 3g is enabled or not. If it is not, a dialog screen prompts the user to exit and turn either one on. If it is on, then the code will continue. I keep getting an error in my logcat about my activity having a leaked window. I am not sure how to solve this issue. Code and logcat below. Any Ideas?

Here's my code:

//create alert dialog for wifi and 3g
connectionDialog = new AlertDialog.Builder(SplashMain.this).create();
Log.d(TAG, "dialog created");
connectionDialog.setTitle("Wifi or 3G not detected. Please enable either Wifi or 3G");
connectionDialog.setButton("Exit", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
            finish();
    }
});

wifiHandler = new Handler();
setContentView(R.layout.splashscreen);  //Make the splash screen load first
Thread splashScreenTimer = new Thread(){ //create a timer for the splash screen
    public void run(){      //create a run class
        Looper.prepare();   //prepare looper
        try{            //methods within the run class
            int screenTimer =0;
            //make it last 3 seconds - create a while loop
            while(screenTimer <3000){
                sleep(100); //100= 1/10th of a second
                screenTimer = screenTimer +100;
            }
            connectionState();  //check wifi stuff
            Log.d(TAG, "checked wifi state");
            if(mobile == true || wifi == true){
                Log.d(TAG, "wifi is true");
                connectionDialog.dismiss();
                startActivity (new Intent("ravebox.dev.sdr.CLEARSCREEN"));
                finish();
                Log.d(TAG, "started activity");
            }
            if(mobile == false || wifi == false){
                Log.d(TAG, "wifi is false");
                wifiHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        Log.d(TAG, "show dialog");
                        connectionDialog.show();
                        Log.d(TAG, "show'd dialog");
                    }
                });
            }//add activity to the manifest
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally{
            //finish();
        }
    }
};
splashScreenTimer.start();

Log cat:

08-30 22:45:32.188: ERROR/WindowManager(334): Activity ravebox.dev.sdr.SplashMain has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405377e0 that was originally added here
08-30 22:45:32.188: ERROR/WindowManager(334): android.view.WindowLeaked: Activity ravebox.dev.sdr.SplashMain has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405377e0 that was originally added here
08-30 22:45:32.188: ERROR/WindowManager(334):     at android.view.ViewRoot.<init>(ViewRoot.java:258)
08-30 22:45:32.188: ERROR/WindowManager(334):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-30 22:45:32.188: ERROR/WindowManager(334):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-30 22:45:32.188: ERROR/WindowManager(334):     at android.view.Window$LocalWindowManager.addView(Window.java:465)
08-30 22:45:32.188: ERROR/WindowManager(334):     at android.app.Dialog.show(Dialog.java:241)
08-30 22:45:32.188: ERROR/WindowManager(334):     at ravebox.dev.sdr.SplashMain$2$1.run(SplashMain.java:90)
08-30 22:45:32.188: ERROR/WindowManager(334):     at android.os.Handler.handleCallback(Handler.java:587)
08-30 22:45:32.188: ERROR/WindowManager(334):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-30 22:45:32.188: ERROR/WindowManager(334):     at android.os.Looper.loop(Looper.java:123)
08-30 22:45:32.188: ERROR/WindowManager(334):     at android.app.ActivityThread.main(ActivityThread.java:3835)
08-30 22:45:32.188: ERROR/WindowManager(334):     at java.lang.reflect.Method.invokeNative(Native Method)
08-30 22:45:32.188: ERROR/WindowManager(334):     at java.lang.reflect.Method.invoke(Method.java:507)
08-30 22:45:32.188: ERROR/WindowManager(334):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-30 22:45:32.188: ERROR/WindowManager(334):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-30 22:45:32.188: ERROR/WindowManager(334):     at dalvik.system.NativeStart.main(Native Method)

解决方案

Here is an answer that shows why this problem occurs: Activity has leaked window that was originally added

Now, in you case you have written this code

if(mobile == true || wifi == true){
      Log.d(TAG, "wifi is true");
      connectionDialog.dismiss();
      startActivity (new Intent("ravebox.dev.sdr.CLEARSCREEN"));
      finish();
      Log.d(TAG, "started activity");
}

In the above code where are you showing the connectionDialog.dismiss(); before dismissing it.

And in this code you are showing the dialog by connectionDialog.show(); but where is the code to dismiss it.

if(mobile == false || wifi == false){
      Log.d(TAG, "wifi is false");
      wifiHandler.post(new Runnable() {
      @Override
      public void run() {
         Log.d(TAG, "show dialog");
         connectionDialog.show();
         Log.d(TAG, "show'd dialog");
      }
});

So, please find a solution for this, it should be something like this.

Show the dialog in starting only, if the wifi is connected cancel() it and move to next activity, if not connected cancel() it after sometime and giving a message that wifi not found or connected.

这篇关于活动渗漏窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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