-2

I have the following code that currently starts another activity:

Intent intent = new Intent(FoodMenuActivity.this, FoodItemActivity.class);      
startActivity(intent); 

Now I want to be able to send some data with to my FoodItemActivityClass. Either some string variables or an object that i have made. How would i go about doing this?

Zapnologica
  • 22,170
  • 44
  • 158
  • 253
  • http://stackoverflow.com/questions/15859445/how-do-you-pass-a-string-from-one-activity-to-another/15859488#15859488. you can pass the string variables using intents. also check this http://androidhub.wordpress.com/2011/08/03/android-intents-for-passing-data-between-activities-part-3/ – Raghunandan Aug 03 '13 at 08:21

2 Answers2

1

In Food Menu Activity:

Intent intent = new Intent(FodMenuActivity.this,FoodItemActivity.class);
intent.putExtra(TEXT,string_u_want_to_send);
startActivity(intent);

In your onCreate, add:

public final static String TEXT=your package name ;(like com.example.app)

In your oncreate in FoodItemActivity:

Intent intent = getIntent();
String data = intent.getStringExtra(FoodMenuActivity.TEXT);
Arjun Bala
  • 108
  • 1
  • 3
  • 10
0

Check out this answer.

The easiest way to do this would be to pass the session id to the signout activity in the intent you're using to start the activity:

Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);
startActivity(intent)

The docs for Intents has more information (look at the section titled "Extras").

Community
  • 1
  • 1
Jon G
  • 1,656
  • 3
  • 16
  • 42