Question: I have a HashMap(String,HashMap(String,Object)) in one of my activity. How do I send this HashMap to another activity via intents

How to add this HashMap to intent extras?

Answer: 
Sending HashMap

```
HashMap<String, Object> hashmapobject =new HashMap<>();
HashMap<String, Object> newhashMap=new HashMap<>();
hashmapobject.put("key",newhashMap);

Intent intent = new Intent(SenderActivity.this, NextActivity.class);
intent.putExtra("hashMapKey", hashmapobject);
startActivity(intent);

```

Receiving HashMap

```
Intent intent = getIntent();    
HashMap<String, Object> hashMapObject = (HashMap<String, Object>)       intent.getSerializableExtra("hashMapKey");
HashMap<String, Object> newhashMap=(HashMap<String, Object>)hashMapObject.get("key");

```
Hi you can use Parcelable :

Write class like this :

```
public class Person implements Parcelable {
String name;
int age;
Date brithDate;

public Person(String name, int age, Date brithDate) {
    this.name = name;
    this.age = age;
    this.brithDate = brithDate;
}

@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(this.name);
    dest.writeInt(this.age);
    dest.writeLong(brithDate != null ? brithDate.getTime() : -1);
}

protected Person(Parcel in) {
    this.name = in.readString();
    this.age = in.readInt();
    long tmpbrithDate = in.readLong();
    this.brithDate = tmpbrithDate == -1 ? null : new Date(tmpbrithDate);
}

public static final Parcelable.Creator<Person> CREATOR = new Parcelable.Creator<Person>() {
    public Persona createFromParcel(Parcel source) {
        return new Person(source);
    }

    public Person[] newArray(int size) {
        return new Person[size];
    }
};

```

Put extra :

```
intent.putExtra("person", new Person("Ahmad",34,date));

```

Get :

```
Bundle data = getIntent().getExtras();
Person person= (Person) data.getParcelable("person");

```

OR you can copy class this site and convert to Parcelable class :

<http://www.parcelabler.com/>

OR you can use this library hrisey

<https://github.com/mg6maciej/hrisey/wiki/Parcelable#details>

Or you can use Android Studio have plugins for this:

* [Android Parcelable code generator](https://github.com/mcharmas/android-parcelable-intellij-plugin) (Apache License 2.0)
* Auto Parcel (The MIT License)
* SerializableParcelable Generator (The MIT License)
* Parcelable Code Generator (for Kotlin) (Apache License 2.0)