I wish to pass the value from 1st activity to 3rd activity.
My 1st activity: CustomizedListview
2nd activity is: SingleMenuItemActivity
3rd activity is: InsertionExample
Here I have to pass the orderid value from CustomisedListView (1st) activity to InsertionExample (3rd) activity.
How can I pass this? I have passed orderid value from 1st activity to second activity. But I can't pass it from 1st activity to 3rd activity. Please help me.
Try this
Intent intent=new Intent(CustomizedListview.this,InsertionExample.class);
intent.putExtra("orderid",getOrderid);
startActivity(intent);
In your third activity
Bundle bundle = data.getExtras();
String getOrderId = bundle.getString("orderid");
I have to passed orderid value from 1st activity to second activity
Send as you send to second activity . Just change name of second activity to third activity.
Or
Just Store Order Id in Shared Preference and get it in third Activity.
SharedPrefernce Example
SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
SharedPreferences.Editor prefsEditor = myPrefs.edit();
prefsEditor.putString("order_id", "5");
prefsEditor.commit();
Get Shared Preference.
SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
String prefName = myPrefs.getString("order_id", "0");
Use SharedPreferences (for small data)to store the data and get this data in you 3 activity
otherwise use internal storage or database(for large data)
You can use intent extra from first activity to second and then pass the same value by extra in another intent from secon to third.
Make the value static, and then use it in the 3rd activity
public static int i;
And then, call it on the 3rd activity:
firstActivity.i;
You can pass the value in 2 ways:
- Either you make a global Class and set the value in that class and
access that class in your 3rd activity
- You can use Intent to send your values from 1st activity to 2nd activity
Intent intent = new Intent (this, 2ndActivity.class);
intent.putExtra ("Value",Value);
startActivity(intent);
And the same you can do for 2nd activity to 3rd activity
Bundle extras = getIntent().getExtras();
if(extras!=null){
Values=extras.getString("value");
}