Dani
Dani

Reputation: 29

bundle.getString() return null value

I want to pass a String between two activities, but when I receive the String, I get a null value. I use the same code in other activities and works perfectly. Any suggestion?

First activity:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_post);





    Glide.with(PostCarrete.this).load(foto)
            .centerCrop()
            .into(imagen);

    next = (ImageView) findViewById(R.id.next) ;
    next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(PostCarrete.this, Compartir.class);
            intent.putExtra("foton",foto);
            startActivity(intent);

        }
    });
}

Second activity:

    Bundle bundle = getIntent().getExtras();
    foto = bundle.getString("foton");

Here the value of bundle is null, so foto's too

Upvotes: 1

Views: 2653

Answers (1)

baskara
baskara

Reputation: 1256

I think it should be:

String foto = getIntent().getStringExtra("foton");

because you are sending also as an extra

Upvotes: 2

Related Questions