title: Sharing state across Android activities
body: <p>I'm having trouble passing along state data between different activities. Right now I have four of them:</p>
  
  <ul>
  <li>A coordinates between activities (a big onActivityResult method) and has no real UI (just a blank layout)</li>
  <li>B adds some data (String)</li>
  <li>C adds some data (taking pictures)</li>
  <li>D shows a review of the data before uploading it, state is deleted afterwards</li>
  </ul>
  
  <p>First I stored the state of this workflow in the instance variables of activity A, but most of the time Android had garbage collected A when returning from B (probably because of orientation changes) so I was getting Null Pointer Exceptions. Then I tried storing state inside a parcelable object, which was created when B returned to A with a result, and then passing along that object to C. It arrives at C fine, but when I'm parceling the object again from C to return to A it doesn't arrive for some reason. This results in another NPE when trying to hand the object from A to D. </p>
  
  <p>In the end, the data needs to be deleted: either by D after uploading or if you close the app halfway and don't complete all the activities. You would start over again at A (or B, which is an actual usable activity).</p>
  
  <p>By now my current structure is feeling way more complex then it should be. I think activity A should be cut out. But I'm unsure on what to implement in its place. <strong>Also I'm unsure on how to make activity C repeatable for 2 or 3 times</strong>, with each time adding data, before going to D. Possible solutions I've found:</p>
  
  <ul>
  <li>Use intents with FLAG_ACTIVITY_FORWARD_RESULT and chain activities together as described in <a href="https://stackoverflow.com/questions/9135449/how-to-return-a-result-through-multiple-activities">How to return a result through multiple activities</a></li>
  <li>Using a Service to manage state</li>
  <li>From <a href="http://www.wrox.com/WileyCDA/WroxTitle/Professional-Android-4-Application-Development.productCd-1118102274.html" rel="nofollow noreferrer">the book</a> that's currently on my desk: using Fragments to store state (with the setRetainInstance method)</li>
  <li>Extending android.app.Application to manage state </li>
  <li>Storing state in SharedPreferences (but where would I do the housekeeping?)</li>
  </ul>
  
  <p>I'm new to Android development... I'll probably could get all of them working sooner or later, but what is the proper solution for my case?</p>