title: How to Iterate through all Bundle objects
body: <p>I am trying to create helper method that would iterate through all <a href="http://developer.android.com/reference/android/os/Bundle.html" rel="noreferrer">Bundle</a> objects, in a <a href="https://stackoverflow.com/a/9310697">generic</a> manner.</p>
  
  <p>By "generic" I mean:</p>
  
  <ol>
  <li>Doesn't need to know the names (keys) of the objects in the Bundle passed as a parameter.</li>
  <li>Doesn't need to change if another member (key) was added to the Bundle in the future.</li>
  </ol>
  
  <p>So far, I figure out the following outline to accomplish that:</p>
  
  <pre><code>  private void bundleToSharedPreferences(Bundle bundle) {
      Set&lt;String&gt; keys = bundle.keySet();
      for (String key : keys) {
          Object o = bundle.get(key);
          if (o.getClass().getName().contentEquals("int")) {
              // save ints
          }
          else if (o.getClass().getName().contentEquals("boolean")) {
              // save booleans
          }
          else if (o.getClass().getName().contentEquals("String")) {
              // save Strings
          }
          else {
              // etc.
          }
      } 
    }
  </code></pre>
  
  <p>Does this approach make sense at all?</p>
  
  <p>Is there a better way of accomplishing this?</p>