【发布时间】:2020-04-19 17:40:41
【问题描述】:
是否可以通过 NavigationContoller 在 BottomNavigation 控制的 Fragment 之间传递 Parcelable 对象/参数?
这是我的应用程序的流程,用户登录到应用程序并打开一个包含底部导航的片段。我能够获得第一个片段的参数(第一个片段使用 NavHostFragment.findNavController(this).navigate(action) 打开)我能够向此操作添加参数并传递值,但 BottomNavigation 没有任何导航指令导航是通过 menuID 完成的。我如何通过捆绑在所有这些底部导航片段之间传递登录用户参数。
我尝试使用 onDestinationChanged() 传递参数
@Override
public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
NavArgument argument = new NavArgument.Builder().setDefaultValue(selectedUser).build();
destination.addArgument("user", argument);
}
但应用程序仍会因java.lang.IllegalArgumentException: Required argument "user" is missing and does not have an android:defaultValue 而崩溃
【问题讨论】:
标签: java android android-fragments navigation bottomnavigationview