本文介绍了Android的活动已经泄露窗口com.android.internal.policy.impl.phonewindow $ decorview问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Android应用程序中工作,显示网络错误。

NetErrorPage.java

 包exp.app;

进口android.app.Activity;
进口android.app.AlertDialog;
进口android.content.Context;
进口android.content.DialogInterface;
进口android.content.Intent;
进口android.net.ConnectivityManager;
进口android.net.NetworkInfo;
进口android.os.Bundle;
进口android.view.KeyEvent;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;

公共类NetErrorPage扩展活动实现OnClickListener {

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.neterrorlayout);
        键重装=(按钮)findViewById(R.id.btnReload);
        reload.setOnClickListener(本);
        showInfoMessageDialog(请检查网络连接,网络警告);
    }

    公共无效的onClick(查看arg0中)
        {
            如果(isNetworkAvailable())
            {
                意图myIntent =新的意图((活动)NetErrorPage.this,MainActivity.class);
                myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                ((活动)NetErrorPage.this).startActivity(myIntent);
                完();
            }
            其他
                showInfoMessageDialog(请检查网络连接,网络警告);
    }

    公共无效showInfoMessageDialog(字符串消息,串题)
       {
        AlertDialog alertDialog =新AlertDialog.Builder(NetErrorPage.this).create();
        alertDialog.setTitle(网络警告);
        alertDialog.setMessage(消息);
        alertDialog.setButton(OK,
                新DialogInterface.OnClickListener(){
                    公共无效的onClick(DialogInterface对话,诠释其)
                    {
                        dialog.cancel();
                    }
                });
        alertDialog.show();
    }

 私人布尔isNetworkAvailable()
    {
        的NetworkInfo ActiveNetwork;
        @燮pressWarnings(未使用)
        字符串IsNetworkConnected;
        @燮pressWarnings(未使用)
        字符串ConnectionType;
        ConnectivityManager connectivitymanager;
        connectivitymanager =(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        尝试
        {
            ActiveNetwork = connectivitymanager.getActiveNetworkInfo();
            ConnectionType = ActiveNetwork.getTypeName();
            IsNetworkConnected =将String.valueOf(ActiveNetwork.getState());
            返回true;
        }
        赶上(异常错误)
        {
                返回false;
        }
    }
}
 

但我得到的错误如下,

 一十一月8号至17号:59:08.019:E /窗口管理器(16460):活动exp.app.NetErrorPage渗漏窗口com.android.internal.policy.impl.PhoneWindow $ DecorView @ 40534a18最初此处添加
十一月8号至17日:59:08.019:E /窗口管理器(16460):android.view.WindowLeaked:活动exp.app.NetErrorPage渗漏最初添加窗口com.android.internal.policy.impl.PhoneWindow$DecorView@40534a18这里
。十一月8日至十七日:59:08.019:E /窗口管理器(16460):在android.view.ViewRoot< INIT>(ViewRoot.java:263)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.view.Window $ LocalWindowManager.addView(Window.java:424)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.app.Dialog.show(Dialog.java:241)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在sync.directtrac.NetError.showInfoMessageDialog(NetErrorPage.java:114)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在sync.directtrac.NetError.onCreate(NetErrorPage.java:26)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:935)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.os.Handler.dispatchMessage(Handler.java:99)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.os.Looper.loop(Looper.java:130)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在android.app.ActivityThread.main(ActivityThread.java:3687)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在java.lang.reflect.Method.invokeNative(本机方法)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在java.lang.reflect.Method.invoke(Method.java:507)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
十一月8号至17日:59:08.019:E /窗口管理器(16460):在dalvik.system.NativeStart.main(本机方法)
 

我寻觅更多...但我没有任何正确的理念来清除此。

我要的是,加载这个页面时,布局应加,应显示对话框。

请帮我清除此错误

注意:我已经试过这也

  @覆盖
    保护无效onResume(){
    super.onResume();
        runOnUiThread(新的Runnable(){
            公共无效的run(){
                showInfoMessageDialog(请检查网络连接,网络警告);
            }
        });

    }
 

解决方案

谢谢你们给了我很多建议。最后,我得到了一个解决方案。这是我已经开始NetErrorPage意图两次。有一次,我已经检查了网络连接的可用性,并开始有意以页开始的事件。第二次,如果页面错误,那么我已经开始在OnReceivedError事件的意图。所以第一次对话框没有关闭,在此之前,被称为第二个对话框。所以,我得到了一个错误。

现在我已经删除了第二个电话,并清除错误: - )

I am working with Android application to show network error.

NetErrorPage.java

package exp.app;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class NetErrorPage extends Activity implements OnClickListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.neterrorlayout);
        Button reload=(Button)findViewById(R.id.btnReload);
        reload.setOnClickListener(this);
        showInfoMessageDialog("Please check your network connection","Network Alert");
    }

    public void onClick(View arg0)
        {
            if(isNetworkAvailable())
            {
                Intent myIntent = new Intent((Activity)NetErrorPage.this, MainActivity.class);
                myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                ((Activity)NetErrorPage.this).startActivity(myIntent);
                finish();
            }
            else
                showInfoMessageDialog("Please check your network connection","Network Alert");
    }

    public void showInfoMessageDialog(String message,String title)
       {
        AlertDialog alertDialog = new AlertDialog.Builder(NetErrorPage.this).create();
        alertDialog.setTitle("Network Alert");
        alertDialog.setMessage(message);
        alertDialog.setButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int which)
                    {
                        dialog.cancel();
                    }
                });
        alertDialog.show();
    }

 private boolean isNetworkAvailable()
    {
        NetworkInfo ActiveNetwork;
        @SuppressWarnings("unused")
        String IsNetworkConnected;
        @SuppressWarnings("unused")
        String ConnectionType;
        ConnectivityManager connectivitymanager;
        connectivitymanager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        try
        {
            ActiveNetwork=connectivitymanager.getActiveNetworkInfo();
            ConnectionType=ActiveNetwork.getTypeName();
            IsNetworkConnected=String.valueOf(ActiveNetwork.getState());
            return true;
        }
        catch(Exception error)
        {
                return false;
        }
    }
}

but i'm getting the error as below,

08-17 11:59:08.019: E/WindowManager(16460): Activity exp.app.NetErrorPage has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40534a18 that was originally added here
08-17 11:59:08.019: E/WindowManager(16460): android.view.WindowLeaked: Activity exp.app.NetErrorPage has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40534a18 that was originally added here
08-17 11:59:08.019: E/WindowManager(16460):     at android.view.ViewRoot.<init>(ViewRoot.java:263)
08-17 11:59:08.019: E/WindowManager(16460):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-17 11:59:08.019: E/WindowManager(16460):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-17 11:59:08.019: E/WindowManager(16460):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-17 11:59:08.019: E/WindowManager(16460):     at android.app.Dialog.show(Dialog.java:241)
08-17 11:59:08.019: E/WindowManager(16460):     at sync.directtrac.NetError.showInfoMessageDialog(NetErrorPage.java:114)
08-17 11:59:08.019: E/WindowManager(16460):     at sync.directtrac.NetError.onCreate(NetErrorPage.java:26)
08-17 11:59:08.019: E/WindowManager(16460):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-17 11:59:08.019: E/WindowManager(16460):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-17 11:59:08.019: E/WindowManager(16460):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-17 11:59:08.019: E/WindowManager(16460):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-17 11:59:08.019: E/WindowManager(16460):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-17 11:59:08.019: E/WindowManager(16460):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 11:59:08.019: E/WindowManager(16460):     at android.os.Looper.loop(Looper.java:130)
08-17 11:59:08.019: E/WindowManager(16460):     at android.app.ActivityThread.main(ActivityThread.java:3687)
08-17 11:59:08.019: E/WindowManager(16460):     at java.lang.reflect.Method.invokeNative(Native Method)
08-17 11:59:08.019: E/WindowManager(16460):     at java.lang.reflect.Method.invoke(Method.java:507)
08-17 11:59:08.019: E/WindowManager(16460):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-17 11:59:08.019: E/WindowManager(16460):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-17 11:59:08.019: E/WindowManager(16460):     at dalvik.system.NativeStart.main(Native Method)

I have searched more... but i don't have any right idea to clear this.

What i want is, when loading this page, layout should be added and dialog should be shown.

Please help me to clear this error

Note: I have tried this also

@Override
    protected void onResume() {
    super.onResume();
        runOnUiThread(new Runnable() {
            public void run() {
                showInfoMessageDialog("Please check your network connection","Network Alert");
            }
        });

    }
解决方案

Thank you Guys to give me many suggestions. Finally I got a solution. That is i have started the NetErrorPage intent two times. One time, i have checked the net connection availability and started the intent in page started event. second time, if the page has error, then i have started the intent in OnReceivedError event. So the first time dialog is not closed, before that the second dialog is called. So that i got a error.

Now I have removed the second call and Cleared error :-).

这篇关于Android的活动已经泄露窗口com.android.internal.policy.impl.phonewindow $ decorview问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:03