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))    {
    ....
}

I think if you replace

String venName = bundle.getString(MainActivity.VENUE_NAME); 

with

String venName = bundle.getString("VENUE_NAME");

it should work.

Here is how I handle my transfer of data from one activity to another:

Sending data to activity called "Projectviewoptions":

Bundle b = new Bundle();
          b.putString("id", str_projectid);
          Projectviewoptions pv = new Projectviewoptions();

Receiving data:

idbundle = getArguments();
String myid = idbundle.getString("id");

The "key" on both sides should be same; in this case "id".

Another way to send data, through intent is:

Send:

Intent intent = new Intent(getActivity(),ViewProjectDetails.class);
                            intent.putExtra("id", myid);
                            startActivity(intent);

Recieve:

String id = getIntent().getExtras().getString("id");

You are wrongly accessing the key which you have added in bundle. Besides getting the String as MainActivity.VENUE_NAME try to directly pass the key name which you have added in bundle as below:

Besides getting string as below :

   //Get the bundle
     Bundle bundle = getIntent().getExtras();
    //Extract the data…
   String venName = bundle.getString(MainActivity.VENUE_NAME);        

Try to get the string using key name as below:

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

Tags:

Json

Android