Skip to content

Instantly share code, notes, and snippets.

@fredgrott
Created September 22, 2015 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredgrott/adc8398c626ca924f204 to your computer and use it in GitHub Desktop.
Save fredgrott/adc8398c626ca924f204 to your computer and use it in GitHub Desktop.
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