There is a library that facilitates the transport of objects between classes.
Is the Parceler!
Follow an example:
Add the following dependencies to your build gradles.:
dependencies {
…
compile 'org.parceler:parceler:1.0.4'
compile 'org.parceler:parceler-api:1.0.4’
}
Example class with values we will carry from a Activity
the other:
Values.class
import org.parceler.Parcel;
@Parcel
public class Valores {
String nome;
String sobrenome;
Integer idade;
Boolean masculino;
String rua;
String bairro;
}
Sending :
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);
Receiving :
@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"));
}
}
You have two choices to make. One would be to use
Bundle
to pass the information between theActivitys
and another would be to useSharedPreferences
!– Igor Mello
Where Javascript Enters?
– Pablo Almeida
Oops sorry I didn’t see the tag
Javascript
, but it might be a tip for him, because I think it might be an alternative!– Igor Mello