Passing an object from between activities needs some extra efforts, there are at least three ways to archive this goal:
- Using a serializable interface
- Using a parcelable interface
- Using Google's Gson library to convert from an object to a JSON string
Scenario
For instance, passing two strings to another activity could be archived like this:
Intent intent = new Intent(context, SecondActivity.class);
intent.putExtra(KEY_DOG_NAME, dogName);
intent.putExtra(KEY_DOG_OWNER, dogOwnerName);
If there are too many parameters, we can encapsulate them into a dog object:
public class Dog {
private String mName;
private String mOwner;
public Dog(String name, String owner ...