While working on the development of some new applications, I have tried transferring complex variables to new intents. For example:
Transferring a single variable, or set of single variable is easily accomplished by adding them to the intent.
1: Intent i = new Intent();
2: i.setClassName("packageName", "packageName.IntentClass");
3: String term = "data to pass";
4: i.putExtra("packageName.term", term);
In the called intent, we then get this data by calling getExtras():
1: Bundle extras = getIntent().getExtras();
2: String term = extras.getString("packageName.term");
However, what if we want to pass more complex data? As you can see above, the data types that can be added as extras are somewhat limited. In order to pass an object, it must first implement either the Parcelable or Serializable class. Our next post will be on how to implement the Parcelable class, followed by a post on how to integrate a data service.