Reputation: 13250
I am trying to pass my variables as shown in my first activity on button click:
It works fine if I retrieve them on 2nd Activity.But I need to directly pass them to third activity instead of 2nd.
Intent intent = new Intent(this, Step3Activity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
String getploc=txtFromTime.getText().toString();
String getfrmdate=txtFromTime.getText().toString();
//Create the bundle
Bundle bundle = new Bundle();
//Add your data to bundle
bundle.putString("pickuploc", getploc);
bundle.putString("fromdate", getfrmdate);
//Add the bundle to the intent
intent.putExtras(bundle);
//Fire that second activity
startActivity(intent);
And in third acitivity i'm getting them as :
//Get the bundle
Intent i = getIntent();
Bundle bundle = i.getExtras();
/*Bundle bundle = getIntent().getExtras();*/
//Extract the data…
String pickuploc = bundle.getString("pickuploc");
String fromdate = bundle.getString("fromdate");
Can anyone guide me the right way of passing them to third activity.
Upvotes: 0
Views: 631
Reputation: 13250
Solved it by using shared Preferences as shown.
SharedPreferences data = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
data.edit().putString("PickLocation", getploc).commit();
data.edit().putString("FromDate", getfrmdate).commit();
and calling it in 3rd Activity as:
SharedPreferences data = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String pickuploc = data.getString("PickLocation","");
String fromdate = data.getString("FromDate","");
Upvotes: 0
Reputation: 4775
In the second activity get the Extras Bundle and set it using putExtras in the intent calling the third Activity.
Or if you want more control copy them manually.
Upvotes: 1