未经检查的警告 - 在编译期间使用 Safe Args 传递数据时

unchecked warnings - during compilation when used Safe Args to pass data

我使用导航组件的安全参数在目标之间传递数据

build.gradle apply plugin: "androidx.navigation.safeargs.kotlin"

MyType.kt

@Keep
@Parcelize
class MyType(
        val type: String,
        val name: String
) : Parcelable

nav_graph.xml

<action android:id="@+id/startMyFragment"
    app:destination="@+id/myFragment">
    <argument
        android:name="myArg"
        app:argType="com.myapp.MyType"
        app:nullable="false" />
</action>

上面的导航图在编译过程中产生了很多警告。有人可以建议如何避免这些警告

 where K,V are type-variables:
     K extends Object declared in class HashMap
     V extends Object declared in class HashMap
 /builds/my-app/app/build/generated/source/navigation-args/debug/com/myapp/MyType.java:19: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type HashMap
       this.arguments.put("myArg", myArg);

提前致谢

在我的 Navgraph 中,参数不在操作中,这里每个 Fragment 都将 Args 发送给另一个:

除了 safeargs 库,还有这些:

def nav_version = '2.3.0'
    // Kotlin
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

导航图:

     <fragment
            android:id="@+id/fragmentX"
            android:name="package.FragmentX"
            android:label="Fragment 1">

        <argument
                android:name="userinput"
                app:argType="package.dataclasses.UserParcel"
                app:nullable="true"
                android:defaultValue="@null" />
        <action
                android:id="@+id/action_fragmentX_to_fragmentY"
                app:destination="@id/fragmentY"
               />
    </fragment>

    <fragment
                android:id="@+id/fragmentY"
                android:name="package.FragmentY"
                android:label="Fragment 2"
              >
          
            <argument
                    android:name="useripnut"
                    app:argType="package.dataclasses.UserParcel"
                app:nullable="true"
                android:defaultValue="@null" />
      
        <action
                android:id="@+id/action_fragmentY_to_fragmentX"
                app:destination="@id/fragmentX"  />
        
    </fragment>

如何在片段 X 中获取数据:

val args = FragmentXArgs.fromBundle(requireArguments())

如何将数据传递给片段 Y:

 val navController = activity?.findNavController(R.id.navHost)
                            navController?.navigate(FragmentXDirections.actionFragmentXToFragmentY(userParcel))