-
Notifications
You must be signed in to change notification settings - Fork 31
Converters usage
Marcin Moskała edited this page Apr 30, 2017
·
2 revisions
Since 0.6, library is allowing to add converters. A converter is an object that is converting arguments from some type to other. Here is a simple example of a converter that is changing int arguments to save them as long:
static class IntToLongConverter implements ArgConverter<Integer, Long> {
@Override
public Long wrap(Integer toWrap) {
return toWrap.longValue();
}
@Override
public Integer unwrap(Long wrapped) {
return wrapped.intValue();
}
}
So if we define now @Arg int i;
then it will be saved as long:
bundle.putLong(L_KEY, new IntToLongConverter().wrap(activity.i));
To use them, there must be added configuration annotation behind any class in project: (suggested is BaseActivity)
@ActivityStarterConfig(converters = { ParcelarArgConverter.class })
or in Kotlin
@ActivityStarterConfig(converters = arrayOf(ParcelarArgConverter::class))
This functionality should me mostly used to pass as an argument objects of not supported types. There are build-in converters:
- Parcelar