We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
项目从 ARouter 迁移 TheRouter 时通过 Bundle 传递的参数不能正确获取 value
NavigatorTestActivity
Bundle bundle = new Bundle(); bundle.putInt("test_int_value", 1); TheRouter.build(HomePathIndex.HOME) .with(bundle) .navigation();
NavigatorTargetActivity
Bundle bundle = getIntent().getExtras(); int intValueFromBundle = bundle.getInt("test_int_value", 0); final TextView textView1 = findViewById(R.id.textview1); textView1.setText("接收int值传递:integer2=" + intValueFromBundle);
integer2=1
Bundle 结构是下面这种
integer2=0
看起来与 ARouter 传递 Bundle 之后获取 Bundle 参数的方式不一致,不是能很平滑的迁移到 TheRouter.
TheRouter
之前旧项目使用 ARouter 时都是使用的
ARouter
ARouter.getInstance().build(path).with(bundle) .navigation(activity, requestCode)
传递参数,然后在对应页面使用 intent.extras?.getBoolean(KEY_WEB_VIEW_CLOSE_MODE, false) 这种方式获取参数,如果迁移到 TheRouter 之后必须使用 @Autowired 方式获取参数改动工作量会比较大。
intent.extras?.getBoolean(KEY_WEB_VIEW_CLOSE_MODE, false)
@Autowired
我看了下源码:
fun with(value: Bundle?): Navigator = withBundle(KEY_BUNDLE, value)
我可以通过下面的方式获取传递的值
Bundle bundle = getIntent().getBundleExtra("therouter_bundle"); int intValueFromBundle = bundle.getInt("test_int_value", 0);
但是写法怪怪的,和以前用 ARouter 的写法也不兼容,是我写法有问题吗?或者有什么好的能够平滑迁移的建议?
The text was updated successfully, but these errors were encountered:
TheRouter.build("") .fillParams { bundle -> bundle.putAll(yourBundle) }.navigation()
参考迁移文档 https://therouter.cn/docs/2022/09/05/01
Sorry, something went wrong.
谢谢
一个简单的解决方法,遇到的可以参考一下
No branches or pull requests
项目从 ARouter 迁移 TheRouter 时通过 Bundle 传递的参数不能正确获取 value
Example code
NavigatorTestActivity
NavigatorTargetActivity
Expected Result
integer2=1
Bundle 结构是下面这种
Actual Result:
integer2=0
Question
看起来与 ARouter 传递 Bundle 之后获取 Bundle 参数的方式不一致,不是能很平滑的迁移到
TheRouter
.之前旧项目使用
ARouter
时都是使用的传递参数,然后在对应页面使用
intent.extras?.getBoolean(KEY_WEB_VIEW_CLOSE_MODE, false)
这种方式获取参数,如果迁移到TheRouter
之后必须使用@Autowired
方式获取参数改动工作量会比较大。我看了下源码:
我可以通过下面的方式获取传递的值
但是写法怪怪的,和以前用
ARouter
的写法也不兼容,是我写法有问题吗?或者有什么好的能够平滑迁移的建议?The text was updated successfully, but these errors were encountered: