Skip to content

Instantly share code, notes, and snippets.

@brianbowden
Created October 8, 2013 18:36
Show Gist options
  • Select an option

  • Save brianbowden/6889382 to your computer and use it in GitHub Desktop.

Select an option

Save brianbowden/6889382 to your computer and use it in GitHub Desktop.
Bundler
import android.os.Bundle;
public class Bundler {
private Bundle bundle;
public Bundler() {
bundle = new Bundle();
}
// Bundle convenience methods
public static Bundle getBundle(String key, String value) {
return Bundler.getInstance().put(key, value).bundle();
}
public static Bundle getBundle(String key, int value) {
return Bundler.getInstance().put(key, value).bundle();
}
public static Bundle getBundle(String key, boolean value) {
return Bundler.getInstance().put(key, value).bundle();
}
// Builder methods
public static Bundler getInstance() {
return new Bundler();
}
public Bundler put(String key, String value) {
bundle.putString(key, value);
return this;
}
public Bundler put(String key, int value) {
bundle.putInt(key, value);
return this;
}
public Bundler put(String key, boolean value) {
bundle.putBoolean(key, value);
return this;
}
public Bundle bundle() {
return bundle;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment