Since annotation processing is the new hip thing to do, I thought I’d jump on the bandwagon ;) Yesterday I wrote two annotation processors to make my life simpler. It doesn’t have a spiffy name like +Jake Whartons butterknife, but hey, you can’t have it all.

The first one deals with Fragment instantiation and arguments. As you might be aware, a Fragment needs to be instantiated with a Bundle to pass the arguments. That usually leads to a static newInstance method where you marshal the passed arguments into the arguments bundle, instantiate the Fragment and set the bundle on it. Using the @Arguments annotation, this process is a lot easier. You just annotate your fields and from that information a <YourFragment>Builder class is generated. The builder can be used to construct the fragment in a type safe way, and it has a static method to “inject” the arguments into the fragment at your convenience.

The second annotation is @Frozen. This annotation generates a <YourClass>State helper class that will save the fields annotated with @Frozen to a bundle or set the fields on your target object. This is very useful in onSaveInstanceState and OnCreate etc.

The code and jar download is on bitbucket here: and is in the public domain. It’s not yet field tested, so be aware that there might still be some subtle bugs. Yes I’m just throwing it out there, hoping that it’s useful to you.

View this post on Google+