0
Good afternoon,
I’m starting to use Android Studio, in the following situation I’m stuck: have the Mainactivity where through a recyclerView I have a listing, by clicking on one of these listings step as parameter to page 2 such item clicked and logged in user, however inside page 2 I have another recyclerView that opens other information on page 3. The app for when I try to go back to page 2 because the parameters that came from Mainactivity no longer exist.
Mainactivity - Where to pass the parameters to page 2:
public void onItemClick(View view, int position) {
Carona carona = listaCaronas.get(position);
Intent i = new Intent(MainActivity.this, CorridaActivity.class );
i.putExtra("carona", carona );
i.putExtra("usuario", usuario );
startActivity( i );
}
Page 2 - Where you have the data of the clicked item and the other Recycler:
//Recupera dados do usuário
Bundle extras = getIntent().getExtras();
if( extras != null ){
if (getIntent().getExtras().containsKey("carona")
&& getIntent().getExtras().containsKey("usuario")) {
usuario = (Usuario) extras.getSerializable("usuario");
carona = (Carona) extras.getSerializable("carona");
//verificaStatusRequisicao();
}
}
That is, when I return from page 3 to page 2 there are no more containsKey("ride") and containsKey("user").
Perhaps to solve this your problem the best way would be to store the variable information for access. This can be done via Sqlite, Sharedpreferences or a global scope variable
– Daniel Saraiva