0

I am using the following code to pass parameters from a tabActivity to an AppCompatActivity called Eventi:

TabActivity:

Intent eventi = new Intent(this,Eventi.class);
eventi.putExtra("title,",title);
eventi.putExtra("testo",desc);

and this is the code I use to recall the parameters which I can retrieve from the onStart() method.

Eventi AppCompatActivity:

 Bundle extras = getIntent().getExtras();
 String not = extras.getString("title");
 String messaggio = extras.getString("message");

Anyway extras is always null. why?

2 Answers2

0

what you should be using when retrieving extras from bundle is...

Bundle extras = getIntent();
String not = extras.getStringExtra("title");
String messaggio = extras.getStringExtra("message");

also check if the variable you are passing has a value.

rmanalo
  • 342
  • 3
  • 23
  • from what i've seen, getArguments() is used by fragments while getIntent() is for getting the extras of an intent. the line of code i've posted works very well. try it – rmanalo Mar 29 '16 at 08:57
  • this is where i got it... http://stackoverflow.com/questions/4233873/how-do-i-get-extra-data-from-intent-on-android – rmanalo Mar 29 '16 at 09:07
0

First Make sure both are activities. Then in tabActivity : Here make sure title and desc are string type, also debug to check they are not null or empty when u startActivity.

Intent eventi = new Intent(this,Eventi.class);
eventi.putExtra("title,",title);
eventi.putExtra("testo",desc);

Next in Eventi AppCompatActivity in the Oncreate() method :

 Bundle extras = getIntent().getExtras();
 String not = extras.getStringExtra("title");
 String messaggio = extras.getStringExtra(***"testo"***);
D Agrawal
  • 471
  • 4
  • 15