-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
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
Use bridge without icepick like state handler libraries #14
Comments
To use public interface StateManager {
void restoreState(@Nullable Bundle bundle);
void saveState(@NonNull Bundle bundle);
} and make your Activities and Fragments implement that and do your actually save-state handling there: public class MainActivity extends Activity implements StateManager {
...
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Bridge.saveInstanceState(this, outState);
}
@Override
public void saveState(@NonNull Bundle bundle) {
bundle.putParcelable("hugeObject", hugeObject);
}
...
} Then your Bridge.initialize(getApplicationContext(), new SavedStateHandler() {
@Override
public void saveInstanceState(@NonNull Object target, @NonNull Bundle state) {
if (target instanceof StateManager) {
((StateManager) target).saveState(state);
}
}
@Override
public void restoreInstanceState(@NonNull Object target, @Nullable Bundle state) {
if (target instanceof StateManager) {
((StateManager) target).restoreState(state);
}
}
}); Something like that should work if you really want to go that route. But personally I think it's just much easier at that point to switch to using a library like |
Hmm, it worked as expected but in any case i have to implement a custom StateManager interface for all old style activities. Better to give same effort for icepick, thank you so much @byencho . |
I'm trying to apply this library without any other state handler library. Is there any workaround to implement it compatible with old style savedInstanceState methods when initializing it? Something like;
As i test, it causes TransactionTooLarge in any case, if there's no @State annotation for objects. Icepick is super nice but i have almost 200 unique activity in my project and lazy to overhaul all :)
The text was updated successfully, but these errors were encountered: