Android Studio transfer objects between activities [closed]

2

Hi, I'm having a problem, and I do not know how to send an object to another activity. They told me that I could through the putExtras (), of the intent. But I could not

    
asked by Fernando Godoy 09.03.2017 в 04:05
source

1 answer

2

To transfer objects in a Bundle you have to do three things:

  • Ensure that the object implements Serializable
  • Use putSerializable(String key, Serializable objeto) to set it to Bundle
  • Use getSerializable(String key) to get it from Bundle in your activity

To implement Serializable you do not have to do anything other than add implements Serializable to the class definition (the typical objects that one uses for the majority already implement it).

When you extract the object from Bundle you have to cast, with or without checking with instanceof first.

MiObjeto objeto = (MiObjeto) bundle.getSerializable("mi_objeto");
    
answered by 09.03.2017 / 05:56
source