PopupWindow $BadTokenException: Unable to add window — token null is not valid

后端 未结 11 2181

I have the following error when showing a PopupWindow. The errors are triggered by the line:

checkInPopup.showAtLocation((ViewGroup) mapView.getParent(), Gra         


        
11条回答
  •  攒了一身酷
    2020-11-27 05:30

    use this method before show

    public static ViewGroup getActivityFirstLayout(Context ctx)
    {
        return (ViewGroup)((ViewGroup) ActivityMaster.getActivity(ctx).findViewById(android.R.id.content)).getChildAt(0);
    }
    
    private boolean activityIsOk(Activity activity)
    {
        boolean s1 = !(activity == null || activity.isFinishing());
    
        if(s1)
        {
            View v = LayoutMaster.getActivityFirstLayout(activity);
            return v.isShown() && ViewCompat.isLaidOut(v);
        }
    
        return false;
    }
    

提交回复
热议问题