Retrieve the containsKey()

Asked

Viewed 33 times

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

1 answer

0

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

If this is the case, you can try to store the data passed by page 1 in an instance variable on page 2 when creating that activity (onCreate() method I imagine). So, when you return from page 3, you can access this variable and not the activity Intent.

I hope it will be useful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.