Retrieve the containsKey ()

0

Good afternoon,

I'm starting to use Android Studio, in the following situation I'm stopped: has the MainActivity where through a recyclerView I have a listing, when clicking on one of these step listings as parameter to page 2 such item clicked and user logged in, however inside page 2 I have another recyclerView that opens other information on a 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 I 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 has the data of the item clicked 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 2 there is no longer the containsKey ("ride") and containsKey ("user").

    
asked by anonymous 24.11.2018 / 16:02

1 answer

0

I must first say that I am not an expert on android and I am not certain about when an Intent is created. I imagine it is possible that when returning from the other activity (page 3), the intent of page 2 is replaced by an intent that represents that return.

If this is the case, you can try to save the data that is passed on page 1 to an instance variable on page 2 when creating this activity (onCreate () method). So, when you get back from page 3, you can access this variable instead of the Activity Intent.

I hope it's useful.

    
26.11.2018 / 11:03