【发布时间】:2023-02-01 02:13:02
【问题描述】:
我正在将捆绑包发送到我的另一个片段的 Home Fragment。但是当应用程序第一次打开时,给我一个错误,因为应用程序一开始没有接受任何捆绑包。顺便说一句,我正在发送和接收这样的捆绑包;
//Sending
val fragment = Notlar()
val bundle = Bundle()
bundle.putInt("categoryId", -99)
fragment.arguments = bundle
findNavController().navigate(R.id.action_kategoriler_to_notlar, bundle)
//Getting (On Home Fragment)
categoryIdBundle = requireArguments().getInt("categoryId",-1)
我试过类似的东西;
try {
categoryIdBundle = requireArguments().getInt("categoryId",-1)
} catch (e : Exception) {
categoryIdBundle = -1
}
但是即使它在一开始就打开了,我发送的包从来没有来过,所以 catch 块总是有效。此时我能做什么?
【问题讨论】: