Search code examples
javaandroidandroid-intentbundlegetstring

String within bundle is null


Here is the code in the first activity:

Bundle UserEntries = new Bundle();
UserEntries.putString("Venue_Name", VenueName);
UserEntries.putString("Event_Name", EventName);
UserEntries.putString("Category", Category);
UserEntries.putString("Region", Region);
Intent openGetData = new Intent(SearchDatabase.this, GetData.class);
openGetData.putExtra("UserEntries", UserEntries);
startActivity(openGetData);

And this is the code in the activty opened:

Intent i = getIntent();
    Bundle Parameters = i.getExtras();
    url = "http://192.168.1.74/android_connect/get_venues.php";
    VenueName = Parameters.getString("Venue_Name");
    EventName = Parameters.getString("Event_Name");
    Category = Parameters.getString("Category");
    Region = Parameters.getString("Region");
    if(VenueName != null){
        phpExtension = ("?Venue_Name=" + VenueName);
    }
    url = (url + phpExtension);

However Venue_Name returns null, i have tested the code and in the first activity it is not null and in the second activity the bundle Parameters is not null, however the string Venue_Name within the bundle in the second activity is. Anyone have any ideas where im going wrong?

Thanks in advance


Solution

  • Do it like this in the first Activity-

    Intent openGetData = new Intent(SearchDatabase.this, GetData.class);
    openGetData.putExtra("Venue_Name", VenueName);
    openGetData.putExtra("Event_Name", EventName);
    openGetData.putExtra("Category", Category);
    openGetData.putExtra("Region", Region);
    startActivity(openGetData);