title: Android: Homescreen Shortcut with Serializable Extra
body: <p>I want to create a homescreen shortcut to an inner activity of my app. <a href="https://stackoverflow.com/a/16873257/3449811">This</a> answer helped to get me started. </p>
  
  <p>Here's the basic code: </p>
  
  <pre><code>Intent shortcutIntent = new Intent(context.getApplicationContext(),
          StationMainActivity.class);
  shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  shortcutIntent.setAction(Intent.ACTION_MAIN);
  
  Intent addIntent = new Intent();
  addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
  addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, stationData.getName());
  addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
          Intent.ShortcutIconResource.fromContext(context.getApplicationContext(),
                  R.drawable.ic_launcher));
  
  addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
  addIntent.putExtra("duplicate", false);
  context.getApplicationContext().sendBroadcast(addIntent);
  </code></pre>
  
  <p>Unfortunately, while it does work to provide an extra of type String the code appears to fail if I try to provide a serializable extra to the shortcutIntent. </p>
  
  <pre><code>    shortcutIntent.putExtra("StationId", (String) stationData.getId());
  </code></pre>
  
  <p>does work. But</p>
  
  <pre><code>    shortcutIntent.putExtra("StationData", stationData);
  </code></pre>
  
  <p>where stationData is a serializable Object does not. So right now I provide all fields of the object as string and recreate the object when the activity is called. This does work but it's cumbersome and dirty code. </p>
  
  <p>Any idea why providing a serializable object does not work in this case? Thanks. </p>
  
  <p>Update: Here's how I try to retrieve the Serializeable: </p>
  
  <pre><code>    stationData = (StationData) intent.getSerializableExtra("StationData");
  </code></pre>
  
  <p>StationData looks like this: </p>
  
  <pre><code>public class StationData implements Serializable {
      private String id; 
      private String name; 
      ...
  
      public StationData(String id, String name, ....) {
        this.id = id; 
        this.name = name; 
        ...
      }
   }
  </code></pre>