对话在方向改变时被摧毁

时间:2013-01-30 11:58:09

标签: android

我有两个类,一个适配器和一个活动,我在我的适配器中有一个对话框,我在我的活动中调用此适配器,当我在对话框启动时更改方向时,对话框被破坏。我试过

<activity android:name=".activity.SearchAttraction" android:configChanges="keyboardHidden|orientation|screenLayout|screenSize" />

    @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);

        }
   Noting is working, getting error at line `dialog.show();`    

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();

        }
        // For Manage Menu..
        else if (result != null
                && result.equalsIgnoreCase(myContext.getResources().getString(
                        R.string.addnewplace))) {
            AttractionData attractionData = new AttractionData();
            createDiloag(attractionData,
                    activity.getResources().getString(R.string.addnewplace));
            this.activity.finish();

        }
        // For About Us..
        else if (result != null
                && result.equalsIgnoreCase(myContext.getResources().getString(
                        R.string.fromaddressbook))) {

            Intent callIntent = new Intent(activity, ProfileActivity.class);
            callIntent.putExtra("ProfileType", Constants.FROM_CONTATCS);
            Log.d(TAG, "start to call On Activity Result Method : ");
            parentActivity.startActivityForResult(callIntent, 100);
            Log.d(TAG, "end to call On Activity Result Method : ");
            this.activity.finish();

        }

        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);
                dialog.show();

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

            }

            this.activity.finish();
        }

这是我的日志

01-30 16:38:31.690: E/WindowManager(2791): android.view.WindowLeaked: Activity org.app.mycity.activity.ABActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@420c3948 that was originally added here
01-30 16:38:31.690: E/WindowManager(2791):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:412)
01-30 16:38:31.690: E/WindowManager(2791):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:312)
01-30 16:38:31.690: E/WindowManager(2791):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
01-30 16:38:31.690: E/WindowManager(2791):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
01-30 16:38:31.690: E/WindowManager(2791):  at android.view.Window$LocalWindowManager.addView(Window.java:554)
01-30 16:38:31.690: E/WindowManager(2791):  at android.app.Dialog.show(Dialog.java:277)
01-30 16:38:31.690: E/WindowManager(2791):  at org.appright.myneighborhood.adaptor.AddressPopUpAdapter.performAction(AddressPopUpAdapter.java:169)
01-30 16:38:31.690: E/WindowManager(2791):  at org.appright.myneighborhood.adaptor.AddressPopUpAdapter$1.onClick(AddressPopUpAdapter.java:93)

我很震惊,感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

基本假设,

我认为,更改方向时不会调用onConfigurationChanged(Configuration newConfig),只需通过调试或将日志放入其中进行检查。

参数

android:configChanges="keyboardHidden|orientation|screenLayout|screenSize"
Android 4.0 +

中的

还不够

尝试使用清单文件的活动代码中的android:configChanges中的其他参数。

类似的东西,

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize"

试试这个,让我知道发生了什么......