How to fetch edittext value from one activity into another activity for string?
pass the value in intent ... but if that activity do not appear in the same flow Use SharedPreferences, store the value in the original activity , retrieve it in the later activity.. Shared Preference code:
SharedPreferences pref = context.getSharedPreferences("PREF_NAME", Context.MODE_PRIVATE);
pref.edit().putString("NAME", editText.getText().toString()).commit();
in other activity
SharedPreferences pref = context.getSharedPreferences("PREF_NAME", Context.MODE_PRIVATE);
String ediTextVal = pref.getString("NAME", "anyDefaultValue");
Intent Solution if both activities are in a flow, IN activity1 with the editText :
Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putExtra("editTextVal", editText.getText().toString);
startActivity(intent);
In activity2 where editText value is needed:
Bundle extras = getIntent().getExtras();
String editTextVal= null;
if(extras !=null && extras.containsKey("editTextVal"))
{
editTextVal= extras.getString("editTextVal");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With