How to apply onConfigurationChanged () in activity with AndroidXMapFragment

0

I modified onConfigurationChanged () in the Search sample code as below to not restart the activity when orientation changes. However, it always dies with the error shown below. Is there any way to solve this?

[Error Messages]

Error log when orientation is changed.

2020-04-06 20:13:47.240 22791-22791/com.lge.arnavigation E/LocationManager: [LGNSS] Disable_PrivacyLocation_Information [tOperator : LGU ] , [privacy_check : 0]
2020-04-06 20:13:47.243 22791-22791/com.lge.arnavigation E/LocationManager: [LGNSS] This device should be enabled location encryption - user build
2020-04-06 20:13:50.689 22791-22791/com.lge.arnavigation E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.lge.arnavigation, PID: 22791
    android.view.InflateException: Binary XML file line #50: Binary XML file line #50: Error inflating class fragment
    Caused by: android.view.InflateException: Binary XML file line #50: Error inflating class fragment
    Caused by: java.lang.IllegalArgumentException: Binary XML file line #50: Duplicate id 0x7f070065, tag null, or parent id 0xffffffff with another fragment for com.here.android.mpa.mapping.AndroidXMapFragment
        at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3212)
        at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:134)
        at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
        at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:336)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.here.android.example.search.MainActivity.onConfigurationChanged(MainActivity.java:61)
        at android.app.ActivityThread.performActivityConfigurationChanged(ActivityThread.java:5118)
        at android.app.ActivityThread.performConfigurationChangedForActivity(ActivityThread.java:4985)
        at android.app.ActivityThread.performConfigurationChangedForActivity(ActivityThread.java:4953)
        at android.app.ActivityThread.handleActivityConfigurationChanged(ActivityThread.java:5376)
        at android.app.servertransaction.ActivityConfigurationChangeItem.execute(ActivityConfigurationChangeItem.java:43)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6853)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)

[MainActivity.java]

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

    switch (newConfig.orientation) {
        case Configuration.ORIENTATION_PORTRAIT:
            setContentView(R.layout.activity_main);
            break;
        case Configuration.ORIENTATION_LANDSCAPE:
            setContentView(R.layout.activity_main);
            break;
        default:
            return;
    }
}

[AndroidManifest.xml]

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

[activity_main.xml]

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">


        <!-- Map Fragment embedded with the map object -->

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <Button
                android:text="Around"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/aroundRequestBtn"
                android:layout_weight="1" />

            <Button
                android:text="Explore"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/exploreRequestBtn"
                android:layout_weight="1" />

            <Button
                android:text="Here "
                android:layout_width="92dp"
                android:layout_height="wrap_content"
                android:id="@+id/hereRequestBtn"
                android:layout_weight="1" />

            <Button
                android:text="Search"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/searchRequestBtn"
                android:layout_weight="1" />

        </LinearLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <fragment
                class="com.here.android.mpa.mapping.AndroidXMapFragment"
                android:id="@+id/mapfragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"/>

            <Button
                android:text="Result List"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/resultListBtn"
                android:layout_alignParentTop="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:visibility="gone" />
        </RelativeLayout>

    </LinearLayout>
android
here-api
asked on Stack Overflow Apr 6, 2020 by joseph lee • edited Apr 10, 2020 by Dharman

1 Answer

0

OnConfiguration method implementation looks correct. Are you trying to inflate a fragment... inside a fragment_layout?

Note: You cannot inflate a layout into a fragment when that layout includes a . Nested fragments are only supported when added to a fragment dynamically. Please try enabling debug mode to locate the exact error.


User contributions licensed under CC BY-SA 3.0