组件化开发架构中,页面跳转
、组件间调用
是至关重要的两大问题,目前Github上已经有多个开源框架,基本都是通过拼接参数来实现页面跳转、获取服务实例。
GRouter 兼容拼接参数方式同时,区别于其他组件化方案推出了安全构造器
方案,把工程内的Activity和服务类的构造器生成在GActivityCenter、GComponentCenter、GTaskCenter、GDelegateCenter类中,方便我们安全地调用,避免了拼接参数容易写错,或者目标类被修改带来的运行错误。
自动生成构造器
,避免拼接参数容易写错问题。GRouter已经在拥有434个Activity、28个Module的千万用户级别APP稳定使用,大家可以放心使用。GRouter 会一直致力于组件化解决方案,如果你有更好的建议,可以提Issues或私聊联系我。如果你觉得还不错,欢迎 star 该 Github 项目,我们会有持续的优化迭代,感谢你的支持!
Activity 页面跳转
// 不推荐
GRouter.getInstance().startActivity(context, "grouter://activity/user?uid=1")
// 不推荐
GRouter.getInstance().activityBuilder("user").put("uid",1).start(context)
// 推荐
GActivityCenter.UserActivity().uid(123).start(context)
下沉接口式 - 组件间服务调用
// 不推荐
val userService = GRouter.getInstance().getComponent("userService") as UserService
// 不推荐
val userService = GRouter.getInstance().getComponent("userService",UserService::class.java)
// 推荐
val userService = GComponentCenter.UserServiceImpl()
非下沉式 - 组件间单任务调用
// 不推荐
val response = GRouter.getInstance().taskBuilder("grouter://task/getUser?uid=1").execute()
// 不推荐
val response = GRouter.getInstance().taskBuilder("getUser").put("uid",1).execute()
// 推荐
val response = GTaskCenter.GetUserTask().uid(1).execute()
// 获取返回值
val user = response.value(User::class.java)
非下沉式 - 反射代理服务
val accountServiceDelegate = GDelegateCenter.AccountService(context)
Copyright 2019 taoweiji
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.