Nice programing

android : configChanges =“orientation”은 조각에서 작동하지 않습니다.

nicepro 2020. 12. 6. 22:06
반응형

android : configChanges =“orientation”은 조각에서 작동하지 않습니다.


내 응용 프로그램 중 일부를 HoneyComb에 적용하려고합니다.

내가 직면 한 문제는 방향 변경 (가로 / 세로)에 대한 내 활동의 파괴입니다.

클래식 활동을 사용할 때 매니페스트에 다음과 같이 썼습니다.

하지만 지금은이 모든 라인이 더 이상 작동하지 않습니다!

이에 대한 해결 방법이 있습니까?

내 코드 :

    <activity android:name=".TwitterActivity" android:label="@string/app_name"
        android:configChanges="keyboardHidden|orientation" />

    <activity android:name=".TwitterActivity$AppListFragment"
    android:configChanges="keyboardHidden|orientation"  />

Honeycomb 3.0 및 호환성 라이브러리 (r1)에 대한 내 경험을 기반으로합니다.

configChange="orientation"방향 변경시 활동 (적용되는)이 다시 생성되는 것을 방지하는 것과 관련하여 조각으로 작업합니다. 당신이 원하는 경우 fragment다시 만들어 활동 재 작성에있을 수 없습니다 다음 전화 setRetainInstance에서 onCreate.

내가 아주 두 번째 매니페스트 항목을하지 않는 뭔가를 누락하지 않는 한, 아닌 AppListFragmentA는 Fragment? 그렇다면 매니페스트의 항목으로 나열되는 이유는 무엇입니까?

SDK 13을 대상으로하는 경우이를 유발할 수있는 새로운 한정자에 대해서는 SO 답변참조하십시오.android:configChanges="orientation|screenSize"


나는 매우 유사한 문제가 있었지만 다양한 버전 (ICS 포함)에서 작동하도록 몇 가지 추가 작업을 수행해야했습니다.

메인 앱 활동에서 Jason이 제공 한 것과 약간 다른 버전을 추가했습니다.

<activity
android:name=".MyMainActivity"
android:configChanges="orientation|keyboardHidden|screenSize" 
android:label="@string/app_name" >

나는 이것을 사전 Honeycomb에서 다음과 같이 작업했습니다.

           <activity
        ....
        android:configChanges="orientation|keyboardHidden" 
        .... >

모든 버전에서 실행되도록 첫 번째 예제를 만들어야했습니다. 저는 현재 이전 버전과의 호환성을 위해 조각과 ActionBarSherlock을 사용하고 있습니다.

또한 저장 및 다시로드 방식도 변경했습니다.

        public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        // Set up webview object
        View v = inflater.inflate(R.layout.webview_layout, container, false);
        webview = (WebView)v.findViewById(R.id.webview_fragment);
        webview.getSettings().setJavaScriptEnabled(true);

        // Check to see if it has been saved and restore it if true
        if(savedInstanceState != null)
        {
            if (savedInstanceState.isEmpty())
                Log.i(tag, "Can't restore state because bundle is empty.");
            else
            {
                if (webview.restoreState(savedInstanceState) == null)
                    Log.i(tag, "Restoring state FAILED!");      
                else
                    Log.i(tag, "Restoring state succeeded.");      
            }

        }
        else 
        {
            // Load web page
            webview.setWebViewClient(new MyWebViewClient());
            webview.getSettings().setPluginsEnabled(true);
            webview.getSettings().setBuiltInZoomControls(false); 
            webview.getSettings().setSupportZoom(false);
            webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);   
            webview.getSettings().setAllowFileAccess(true); 
            webview.getSettings().setDomStorageEnabled(true);
            webview.loadUrl(mTabURL);       
        }
        return v;
    }

저장 인스턴스 상태 메소드의 코드 :

       @Override
    public void onSaveInstanceState(Bundle outState)
    {
        if(webview.saveState(outState) == null)
            Log.i(tag,"Saving state FAILED!");
        else
            Log.i(tag, "Saving state succeeded.");      
    }

도움이 되었기를 바랍니다.


Up to API 13 there was a new value to the configChanges attribute, screenSize

So if you're using large screens make sure to add screenSize in your configChanges attribute:

        android:configChanges="orientation|keyboardHidden|screenSize"

Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android:configChanges="orientation|screenSize". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).


I was having this same problem (i.e., activity restarting) even without fragments.

I changed:

android:configChanges="orientation|keyboardHidden"

to:

android:configChanges="orientation|keyboardHidden|screenSize" 

That prevent the activity from restarting.


I know this is quite late answer, but I recently faced this issue and was able to resolve this for Fragment Activity.

1) In Manifest,

      android:configChanges="orientation|keyboardHidden|screenSize"

2) In Class file, override the onSaveInstanceState(Bundle outState). Thats it! Enjoy :)


In Manifest file, inside activity add this line
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" .


Add this to Manifeast.Xml

<android:configChanges="orientation|screenSize" >

Its work for you.

참고URL : https://stackoverflow.com/questions/7139488/androidconfigchanges-orientation-does-not-work-with-fragments

반응형