Newer version(s) are at https://bitbucket.org/littlerobots/bundles


This is an annotation processor for making Fragment construction type safe, and making saving state easier.

There are two annotations provided, @Argument for fragment arguments and @Frozen for saving and restoring state in onSaveInstanceState.


Construction of Fragments can be painful if you need to pass arguments to construct them. The problem is that you need to construct a Bundle,
put values in it by key and set it on the Fragment instance. This is not only cumbersome to do, but also not very type safe.

The @Argument annotation helps by generating a builder class for your Fragment. For example:

public class TestFragment extends Fragment {
    boolean mCheese;
    int mTotal;

    public void onCreate(Bundle savedInstanceState) {
        // Use the generated builder class to "inject" the arguments on creation
        // you can use a static import to shorten this line to injectArguments(this)

To construct this fragment you'd do something like this:

TestFragment fragment = new Test2FragmentBuilder(false).build();
TestFragment fragment2 = new Test2FragmentBuilder(false).total(10).build();

Required arguments must be passed into the builder constructor, while non-required arguments have a builder method.


The @Frozen annotation aids with saving Activity or Fragment state in onSaveInstanceState and restoring it in onCreate or other places.
A class <YourActivityName>State is generated for this purpose. Here's an example:

package test;

import static test.MyActivityState.restoreInstanceState;
import static test.MyActivityState.saveInstanceState;
import android.app.Activity;
import android.os.Bundle;

import com.neenbedankt.bundles.annotation.Frozen;

public class MyActivity extends Activity {
    String mName;
    boolean mCheeseActive;

    protected void onCreate(Bundle savedInstanceState) {
        restoreInstanceState(this, savedInstanceState);

    protected void onSaveInstanceState(Bundle outState) {
        saveInstanceState(this, outState);


Either build from source using Gradle, or download the jar