Android: "Window problem" dialog when changing orientation

I have two classes, one adapter and one action, I have a dailog that I display in the adapter. I am getting an error when I tried to change the screen orientation. I tried to override the below code in my activity. but nothing works

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
          Log.d(TAG, "configuration changed : " +newConfig);

    }

      

below is my adapter code

public AddressPopUpAdapter(Activity activity, Activity parent,
            int resourceId, ArrayList<PopUpMenu> items, int renderer) {
        super(activity, resourceId, items);
        this.items = items;
        this.renderer = renderer;
        this.activity = activity;
        this.parentActivity = parent;
        popupMenuUtils = new PopupMenuUtils();
        dialog = new Dialog(parentActivity);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        popUpMenu = items.get(position);
        Log.d(TAG, "location" + popUpMenu);
        if (popUpMenu == null) {
            return null;
        }
        Log.d(TAG, "location" + popUpMenu);
        View view = convertView;
        if (view == null) {
            LayoutInflater layoutInflater = (LayoutInflater) (getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE));
            view = layoutInflater.inflate(renderer, null);

        }

        final LinearLayout popupmain = (LinearLayout) view
                .findViewById(R.id.popupmain);

        popupmain.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                v.setEnabled(false);
                performAction(v, activity);

            }
        });

        if (position % 2 == 0) {

            view.setBackgroundResource(R.drawable.listshape);

        } else {
            view.setBackgroundResource(R.drawable.favoritebody);
        }
        return view;
    }

    public void performAction(View v, Activity activity) {

        Context myContext = v.getContext();
        PopUpMenu popUpMenu = (PopUpMenu) v.getTag();
        String result = popUpMenu.getMenuName();
        if (result != null
                && result.equalsIgnoreCase(myContext.getResources().getString(
                        R.string.savecurrentlocation))) {
            getCurrentLocation();

        }

        else if (result != null
                && result.equalsIgnoreCase(myContext.getResources().getString(
                        R.string.distancebetween))) {
            AttractionService service = AttractionService
                    .getInstance(parentActivity.getApplicationContext());
            ArrayList<AttractionData> allMenuSearchList = service
                    .getAllAttractions(true, Constants.field, Constants.order);

            if (allMenuSearchList != null && !allMenuSearchList.isEmpty()) {

                dialog.setContentView(R.layout.pickdestination);
                ListView listPlace = (ListView) dialog
                        .findViewById(R.id.listPlace);
                PlaceAdapter placeAdapter = new PlaceAdapter(parentActivity,
                        allMenuSearchList, R.layout.pickcity, dialog,
                        R.string.pickstartingpoint, null);
                listPlace.setAdapter(placeAdapter);
giving error here----------->   dialog.show();

            } else {
                Toast.makeText(parentActivity, R.string.nonavigationtolink,
                        Toast.LENGTH_SHORT).show();

            }

            this.activity.finish();
        }

      

Any help is appreciated.

+3


source to share


3 answers


The point is that you don't dismiss () your dialog and complete the action, so when you change the orientation, it will get the preview state of the Dialog.

So try to dismiss() your dialog before you finish your activity.



See details in other cases:

+2


source


Consistent with the hints above: chintan / Stephan; I made the AlertDialog link global to the Activity and dismissed inDestroy ():

if (ad!=null) {
 ad.dismiss();
 ad=null;
}

      



When rotating, no more leakage errors are recorded.

I would hate to consider these configChanges options, because they could mess things up if you already have specific layouts for terrain or such.

+1


source


A workaround for this problem is to add

android:configChanges="orientation"

      

for your activity in the manifest.

-2


source







All Articles