Passing data from one activity to another using bundle – not displaying in second activity

Two ways you can send the data. This is how you are sending it at the moment. And there is nothing wrong with it.

//Create the bundle
Bundle bundle = new Bundle();
//Add your data from getFactualResults method to bundle
bundle.putString("VENUE_NAME", venueName);
//Add the bundle to the intent
i.putExtras(bundle);
startActivity(i);

In you code (second Activity) however, you are referring to the key in the Bundle as MainActivity.VENUE_NAME but nothing in the code suggests that you have a class that returns the value as the actual key name send with the Bundle. Change your code in the second Activity to this:

Bundle bundle = getIntent().getExtras();

//Extract the data…
String venName = bundle.getString("VENUE_NAME");        

//Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(venName);

You can check in your second Activity if the Bundle contains the key using this and you will know that the key is not present in the Bundle. The correction above, however, will get it working for you.

if (bundle.containsKey(MainActivity.VENUE_NAME))    {
    ....
}

Leave a Comment