Bundle coming null

1

I'm trying to pass parameters a value from one screen to another, but in the other it gets null, see:

Screen 1:

Intent telaWeb = new Intent(SegmentoView.this, ViewWeb.class);
Bundle bundleParametro = new Bundle();
telaWeb.putExtras(bundleParametro);
bundleParametro.putString("link", urlStr);
startActivity(telaWeb);

Screen 2:

Intent dadosRecebidos = getIntent();
if(dadosRecebidos != null){
    Bundle parRecebidos = dadosRecebidos.getExtras();
    if(parRecebidos != null) {
        URL =  parRecebidos.getString("link");
    }
}

However, the value is null. What's wrong?

    
asked by anonymous 27.11.2014 / 08:23

2 answers

0

The problem is that in your code, you are putting Bundle in Intent before defining the extras of it:

Bundle bundleParametro = new Bundle();
telaWeb.putExtras(bundleParametro);
bundleParametro.putString("link", urlStr);

Just set your Bundle before placing it inside your Intent , and on your other Activity , retrieve it normally:

Bundle bundleParametro = new Bundle();
bundleParametro.putString("link", urlStr);
telaWeb.putExtras(bundleParametro);

Another way to do this is to place the extras directly in your Intent , for example:

Intent telaWeb = new Intent(SegmentoView.this, ViewWeb.class);
telaWeb.putExtras("link", urlStr);
startActivity(telaWeb);

And, in your other Activity :

...

if (getIntent() != null && getIntent().hasExtras("link"){
    URL =  getIntent().getExtras().getString("link");
}

...
    
27.12.2014 / 14:10
0

I do not use the Bundle, no. Do this to see if it works: telaWeb.putExtras("link", urlStr) , and delete the lines that the bundleParametro object uses.

    
27.11.2014 / 12:10