Comments (4)
List可以直接通过bundle传递,List 可以通过Parcelable
from ddcomponentforandroid.
DDComp这边代码很久没有维护过了,记忆中,在使用Autowired的时候,当时提供的功能并不是很多。
在JIMU那边最新的代码里,我也仅提供了这些支持:
// Primitive
if (typeMirror.getKind().isPrimitive()) {
return element.asType().getKind().ordinal();
}
switch (typeMirror.toString()) {
case Constants.BYTE:
return Type.BYTE.ordinal();
case Constants.SHORT:
return Type.SHORT.ordinal();
case Constants.INTEGER:
return Type.INT.ordinal();
case Constants.LONG:
return Type.LONG.ordinal();
case Constants.FLOAT:
return Type.FLOAT.ordinal();
case Constants.DOUBEL:
return Type.DOUBLE.ordinal();
case Constants.BOOLEAN:
return Type.BOOLEAN.ordinal();
case Constants.STRING:
return Type.STRING.ordinal();
default: // Other side, maybe the PARCELABLE or OBJECT.
if (types.isSubtype(typeMirror, parcelableType)) { // PARCELABLE
return Type.PARCELABLE.ordinal();
}
// else if (types.isSubtype(typeMirror, serializableType)) {
// return Type.SERIALIZABLE.ordinal(); 暂不支持需要做转型
// }
else { // For others
return Type.OBJECT.ordinal();
}
显然,这边只会走到OBJECT的处理逻辑中,也就是利用json工具做序列化/反序列化.即使用Bundle#putParcelableArrayList(String key, ArrayList<? extends Parcelable> value)的形式去传递,也无法用Autowired取出来并赋值。只能自己去Intent的Bundle中读取。或者用一个对象类去包裹一下这个List(注意需要去泛化)
PS:经过长时间的考虑,我越发觉得UI路由是个有点花里胡哨的功能。但是自动取值还是比较有意义的,在我另一个项目中,是尝试过对绝大多数Bundle中支持的数据做智能推断的。目前可以支持这么多(根据名字推测一下):
有空的话我会考虑下扩展自动取值注入的功能,代码应该会在JIMU仓库提交。
from ddcomponentforandroid.
// UI transfer with Bundle
private void goToShareActivityWithBundle() {
Author author = new Author();
author.setName("Margaret Mitchell");
author.setCounty("USA");
Bundle bundle = new Bundle();
bundle.putString("bookName", "Gone with the Wind");
bundle.putString("author", JsonService.Factory.getInstance().create().toJsonString(author));
UIRouter.getInstance().openUri(getActivity(), "DDComp://share/shareBook", bundle);
}这是 Demo 中的数据传递,如果传递 List 数据,怎么传递?
@Autowired
List author;
接收数据时,这么写,编译报错:错误: 需要<标识符>@OverRide
public void inject(Object target) {
jsonService = JsonService.Factory.getInstance().create();
SecondActivity substitute = (SecondActivity)target;
if (null != jsonService) {
substitute.children = jsonService.parseObject(substitute.getIntent().getStringExtra("children"), List.class);
} else {
Log.e("AutowiredProcessor", "You want automatic inject the field 'children' in class 'SecondActivity' , but JsonService not found in Router");
}
substitute.title = substitute.getIntent().getStringExtra("title");
}这是编译生成的类,List.class 这个地方编译不通过,Cannot select from parameterized type
DDComponent
很久没维护了,其实问题还是挺多的,建议使用下面的方案,持续更新,框架贴近系统,不使用晦涩难懂的配置,并且功能强大
Component
from ddcomponentforandroid.
DDComp这边代码很久没有维护过了,记忆中,在使用Autowired的时候,当时提供的功能并不是很多。
在JIMU那边最新的代码里,我也仅提供了这些支持:// Primitive if (typeMirror.getKind().isPrimitive()) { return element.asType().getKind().ordinal(); } switch (typeMirror.toString()) { case Constants.BYTE: return Type.BYTE.ordinal(); case Constants.SHORT: return Type.SHORT.ordinal(); case Constants.INTEGER: return Type.INT.ordinal(); case Constants.LONG: return Type.LONG.ordinal(); case Constants.FLOAT: return Type.FLOAT.ordinal(); case Constants.DOUBEL: return Type.DOUBLE.ordinal(); case Constants.BOOLEAN: return Type.BOOLEAN.ordinal(); case Constants.STRING: return Type.STRING.ordinal(); default: // Other side, maybe the PARCELABLE or OBJECT. if (types.isSubtype(typeMirror, parcelableType)) { // PARCELABLE return Type.PARCELABLE.ordinal(); } // else if (types.isSubtype(typeMirror, serializableType)) { // return Type.SERIALIZABLE.ordinal(); 暂不支持需要做转型 // } else { // For others return Type.OBJECT.ordinal(); }
显然,这边只会走到OBJECT的处理逻辑中,也就是利用json工具做序列化/反序列化.即使用Bundle#putParcelableArrayList(String key, ArrayList<? extends Parcelable> value)的形式去传递,也无法用Autowired取出来并赋值。只能自己去Intent的Bundle中读取。或者用一个对象类去包裹一下这个List(注意需要去泛化)
PS:经过长时间的考虑,我越发觉得UI路由是个有点花里胡哨的功能。但是自动取值还是比较有意义的,在我另一个项目中,是尝试过对绝大多数Bundle中支持的数据做智能推断的。目前可以支持这么多(根据名字推测一下):
有空的话我会考虑下扩展自动取值注入的功能,代码应该会在JIMU仓库提交。
使用这个吧,你不会失望的
Component
from ddcomponentforandroid.
Related Issues (20)
- 项目报错Unable to find a matching configuration of project HOT 11
- android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? HOT 3
- 在实际公司组件化git部署用的哪种方式
- 打包后找不到子组件的类,怎么解决? HOT 1
- 建议
- basicres添加资源后编译失败 HOT 1
- 同时集成Bubly的Tinker1.9.6热修复时,打补丁包失败 HOT 2
- 关于数据传递的问题 HOT 1
- 修改组件文件后,运行app,报错Failed to delete 组件名字\build\intermediates\intermediate-jars\debug\classes.jar HOT 5
- 没明白 AppShareBean不想将一些类下沉如何处理 是如何处理的 HOT 1
- 低版本无法运行的问题 HOT 1
- 低版本无法运行的问题
- 关于组件化dagger android使用相关问题 HOT 2
- gradle 5.1.1 BUG HOT 1
- 模块引入R文件报红
- 组件化,activity之间的共享动画如何处理呀? HOT 1
- 组件化库维护问题
- 依赖包版本compile 'com.android.support:appcompat-v7:26.+'
- 框架不支持App Bundle
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ddcomponentforandroid.