简体   繁体   中英

android activity`s onCreate called twice

I call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); at the beginning of the onCreate function, that is why it is called twice but I read that if I add
android:configChanges="keyboardHidden|orientation|screenSize" to the activity`s XML file it should not be called twice, Ive also overriden the OnConfingChanges function like this:

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

this is how my XML file of the activity looks like:

<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/topedLayout"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >

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

    </activity>

    <ScrollView
        ... >

        <LinearLayout
            ... >

            <RelativeLayout
                ... >

                <TextView
                    ... />

                <LinearLayout
                    ... >

                    <TextView
                    ... />

                    <Button
                        ... />

                    <Button
                        ... />

                    <Button
                        ... />
                </LinearLayout>
            </RelativeLayout>

            <ProgressBar
                ... />         
        </LinearLayout>
    </ScrollView>

    <GridView
        ... >
    </GridView>
</LinearLayout>

I assume that definitions of these xml components arent relevant thats why I removed them for simplicity

These lines need to put in manifest.xml file where your activity is define not in layout file.

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

    </activity>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM