You should not regularly perform an Intent to "return" to an Activity unless you have implemented loading the data from a persistent source, such as a database or file.
What you want to do can be achieved by simply adding the onBackPressed()
method to your Activity
B:
@Override
public void onBackPressed() {
super.onBackPressed();
this.finish();
}
In this way, by clicking on the "back" button of your device, Activity B is closed and you return to Activity A, which was previously loaded and you do not have to reload it.
If you want to send data from Activity B
to Activity A
then you can do it using a bundle
with the data and these are sent in a Intent
, you can review this question:
Send data between activities
Send the data in the bundle and send it in Intent
:
bundle.putString("Location", mList.get(position));
bundle.putInt("Type",3);
Intent intent = new Intent(mContext, ActivityA.class);
intent.putExtras(bundle);
mContext.startActivity(intent);
To receive them in Activity A, you can do it within the onCreate()
method:
Bundle parametros = this.getIntent().getExtras();
String datos = "";
int tipo = 0;
if(parametros !=null){
String datos = parametros.getString("Location");
int tipo = parametros.getInt("Type");
}
and later these values can be added to your EditText
, for example:
editTextDatos.setText(datos);
editTextDatos.setText(String.valueOf(tipo)); //* Los valores int debes convertirlos a String para usar el método setText()