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 onClick
and onCreate
for the current and future activities, respectively.
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 onClick
and changing venueName
in the bundle.putString("VENUE_NAME", venueName);
to searchTerm
. 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 venueName
?
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);
}
Method in second activity that should receive the intent and bundle and display it:
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 >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
Thanks for your help. Very much appreciated.