Passing data from one activity to another, does not validate the Key

1

a query.

I try to send data through a variable from one activity to another, but I can not extract the value.

I send it this way:

Intent intent = new Intent(this, EssenMain.class);
        intent.putExtra("foto",account.getPhotoUrl());
        startActivity(intent);

And I receive it in this way in the other activity:

Bundle bundle = this.getIntent().getExtras();
    if(bundle !=null) {
        String fotoString = bundle.getString("foto");

But it is the case that although the data is in the bundle, I can not pass it to the String fotoString variable, which acquires a value of null.

This is validated in the debug mode, of which I attach an image.

Please your help and thank you

    
asked by Disney Guevara 25.06.2018 в 23:55
source

2 answers

0

Although the value of foto is in the bundle and you correctly extract it to the variable fotoString ,

It may be due to two causes,

1) One is that your project is not synchronized, you can clean it and rebuild it with Build > Clean Proyect

2) It may be happening that the load() of Glide method is taking the value of a class variable that is not the one you are declaring in a previous line.

Rename the variable fotoString so that it does not take the one with a null value.

Update: According to the above, it seems to me that it's just a synchronization issue, so I suggest you stop and build your project again.

Something similar to this is happening, if I do not initialize urlPhoto that I use in Glide (blue variable) this will have no value. In your case the variable is within the if therefore it should be overwritten, build your project again.

    
answered by 26.06.2018 в 00:28
0

solve it this way.

Intent intent = new Intent(this, EssenMain.class);
        data = account.getPhotoUrl().toString();
        intent.putExtra("foto",data);
        startActivity(intent);

I converted the content to String, and I stored it in the variable and if it passed without inconvenience, it was not possible to do it in the way previously stated because there was no correspondence of content types with the type of variable.

Bundle bundle = this.getIntent().getExtras();
    if(bundle !=null) {
        String fotoString = bundle.getString("foto");
        Glide.with(this).load(fotoString).into(imageView);
    }

Thanks to everyone and greetings

    
answered by 26.06.2018 в 02:02