0

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.

Rohit Sharma
  • 976
  • 4
  • 15
  • 32
Krishna Veni
  • 2,139
  • 8
  • 25
  • 52

7 Answers7

3

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");
Akshay
  • 2,452
  • 3
  • 33
  • 51
1

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");
Chirag
  • 55,270
  • 29
  • 150
  • 194
1

You can pass the value in 2 ways:

  1. Either you make a global Class and set the value in that class and access that class in your 3rd activity
  2. 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");
    }
Rohit Sharma
  • 976
  • 4
  • 15
  • 32
raghav chopra
  • 797
  • 3
  • 8
  • 25
1

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.

slezadav
  • 5,936
  • 6
  • 33
  • 61
0

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;
Rohit Sharma
  • 976
  • 4
  • 15
  • 32
Aditya Nikhade
  • 1,345
  • 10
  • 15
  • It might be better to store it not in static value but in a singleton, e.g. extend Application class and store where. – sandrstar Sep 05 '12 at 13:20
  • If your app comes back on the third activity after low memory condition, this will have the value of `""` and therefore can cause unexpected crashes etc. (unless you persist saveData to Bundle inside BaseActivity.onSaveInstanceState and restore it strictly once, and your third Activity is singleTask so you can't potentially alter the global variable read by multiple instances of third Activity.) – EpicPandaForce Mar 30 '19 at 15:55
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)

Rajendra
  • 1,660
  • 14
  • 17
0
//your 1st activity (CustomizedListview)
             
String str=txtView.getText().toString();

Intent i=new Intent(getApplicationContext(),SingleMenuItemActivity.class);
i.putExtra("message",str);

startActivity(i);

    //your 2nd Activity (SingleMenuItemActivity)


String str= getIntent().getStringExtra("message");

Intent i = new Intent(getApplicationContext(), InsertionExample.class);

i.putExtra("message", str);

startActivity(i);

    //you 3rd Activity (InsertionExample)


Intent int=getIntent();

String str= int.getStringExtra("message");

txtView.setText(str);
Suraj Rao
  • 28,186
  • 10
  • 88
  • 94