视图未附加到窗口管理器

时间:2014-03-01 20:19:15

标签: android textview window-managers

我的应用有问题


    03-01 21:07:49.796: E/AndroidRuntime(13231): FATAL EXCEPTION: main
    03-01 21:07:49.796: E/AndroidRuntime(13231): java.lang.RuntimeException: Unable to destroy activity {pl.gosell.ghmaster/pl.gosell.ghmaster.activity.ActSklep}: java.lang.IllegalArgumentException: View not attached to window manager
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2676)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2694)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.app.ActivityThread.access$2100(ActivityThread.java:117)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.os.Handler.dispatchMessage(Handler.java:99)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.os.Looper.loop(Looper.java:130)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at java.lang.reflect.Method.invokeNative(Native Method)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at java.lang.reflect.Method.invoke(Method.java:507)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at dalvik.system.NativeStart.main(Native Method)
    03-01 21:07:49.796: E/AndroidRuntime(13231): Caused by: java.lang.IllegalArgumentException: View not attached to window manager
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.view.Window$LocalWindowManager.removeView(Window.java:432)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at pl.gosell.ghmaster.layout.OverlayView.removeOverlay(OverlayView.java:51)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at pl.gosell.ghmaster.activity.ActSklep.onActivityDestroy(ActSklep.java:641)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at com.android.lifter.activity.ActivityBase.onDestroy(ActivityBase.java:338)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2663)
    03-01 21:07:49.796: E/AndroidRuntime(13231):    ... 11 more

我使用字母边栏,并使用OverlayView类来显示字符


    public static View initOverlay(LayoutInflater layoutInflater,
                WindowManager windowManager) 
        {
            overlayTextView = (TextView) layoutInflater.inflate(
                    R.layout.selection_overlay_textview, null);

            overlayTextView.setVisibility(View.INVISIBLE);

            lp = new WindowManager.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_APPLICATION,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
                    PixelFormat.TRANSLUCENT);

            windowManager.addView(overlayTextView, lp);
            return overlayTextView;
        }

        public static void removeOverlay(LayoutInflater layoutInflater,
                WindowManager windowManager)
        {
            if(overlayTextView != null)
            {
                windowManager.removeView(overlayTextView);
            }

        }

活动法案:


    @Override
        protected void onActivityCreate()  //this metod call in onCreate() Activity
        {
    ...

            overlayTextView = (TextView) OverlayView.initOverlay(this.getLayoutInflater(),
                    (WindowManager) this.getSystemService(Context.WINDOW_SERVICE));
            overlayTextView.setVisibility(View.INVISIBLE);
    ...
    }

并销毁:



    @Override
        protected void onActivityDestroy()      //this metod call in onDestroy() Activity
        {
            OverlayView.removeOverlay(this.getLayoutInflater(),
                    (WindowManager) this.getSystemService(Context.WINDOW_SERVICE));
        }

我做错了什么?

0 个答案:

没有答案