There is a library that facilitates the transport of objects between classes.
It's the Parceler !
Here's an example:
Add the following dependencies to your build.gradures :
dependencies {
…
compile 'org.parceler:parceler:1.0.4'
compile 'org.parceler:parceler-api:1.0.4’
}
Sample class with values that we will carry from one Activity
to another:
Values.class
import org.parceler.Parcel;
@Parcel
public class Valores {
String nome;
String sobrenome;
Integer idade;
Boolean masculino;
String rua;
String bairro;
}
Shipping :
final Intent intent = new Intent(this, Step1.class);
Valores valores = new Valores();
valores.nome = "Thiago";
valores.sobrenome = "Domacoski";
valores.idade = 32;
intent.putExtra("valores", Parcels.wrap(valores));
startActivity(intent);
Reception :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_step1);
if(null != getIntent().getParcelableExtra("valores")){
Valores valores = Parcels.unwrap(getIntent().getParcelableExtra("valores"));
}
}