Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
BaseSavingState
package com.grottworkshop.gwsbase;
import android.os.Bundle;
import java.util.List;
@SuppressWarnings("unused")
public abstract class BaseSavingState implements BaseSaveable {
public List<? extends BaseSaveable> componentsToSave;
private BaseSavingState mInstance;
/**
* Format, ie how to ove-ride
*
* <code>
*
* public init(ObjectOne objectOne, ObjectTwo){
* componentsToSave = (Arrays.asList(
* objectyOne,
* objectTwo));
* }
*
*
*
* </code>
*
* Make sure to use your extended BaseSavingStateProvider.getInstance to
* grab a singleton in initGlobalSingletons() of your extended appclass
* see javadoc of BaseSavingStateProvider
*
*/
public BaseSavingState(){
}
@Override
public void saveInstanceState(Bundle bundle) {
Bundle instanceState = new Bundle();
for (BaseSaveable saveable : componentsToSave) {
saveable.saveInstanceState(instanceState);
}
bundle.putBundle("global-state", instanceState);
}
@Override
public void restoreInstanceState(Bundle bundle) {
if (bundle == null) {
return;
}
Bundle instanceState = bundle.getBundle("global-state");
if (instanceState == null) {
return;
}
for (BaseSaveable saveable : componentsToSave) {
saveable.restoreInstanceState(instanceState);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.