Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing data from one activity to another using bundle - not displaying in second activity
    primarykey
    data
    text
    <p>I'm currently trying to take data acquired through a REST API call, parse it for the information I need, and then pass that information to a new activity. I'm using the Asynchronous HTTP Client from loopj.com for the REST client, and then using the below code for my <code>onClick</code> and <code>onCreate</code> for the current and future activities, respectively. </p> <p>Eclipse does not pass me any errors for any of my code, but when I try to run in the emulator, I get nothing (i.e. blank white screen) when the new activity/view opens. I've tried to code with a different URL in my REST CLIENT, but I still see nothing. I even took the API call out of the equation by commenting out the try/catch in <code>onClick</code> and changing <code>venueName</code> in the <code>bundle.putString("VENUE_NAME", venueName);</code> to <code>searchTerm</code>. Still, the new view comes up but nothing is displayed. What is not being passed, or what am I forgetting to make the second activity show the <code>venueName</code>?</p> <pre><code>public void onClick(View view) { Intent i = new Intent(this, ResultsView.class); EditText editText = (EditText) findViewById(R.id.edit_message); String searchTerm = editText.getText().toString(); //call the getFactualResults method try { getFactualResults(searchTerm); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } //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); //Fire the second activity startActivity(i); } </code></pre> <p>Method in second activity that should receive the intent and bundle and display it:</p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Get the message from the intent //Intent intent = getIntent(); //String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); //Get the bundle Bundle bundle = getIntent().getExtras(); //Extract the data… String venName = bundle.getString(MainActivity.VENUE_NAME); //Create the text view TextView textView = new TextView(this); textView.setTextSize(40); textView.setText(venName); //set the text view as the activity layout setContentView(textView); if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) { getActionBar().setDisplayHomeAsUpEnabled(true); } } </code></pre> <p>Thanks for your help. Very much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload