I have an activity where a series of fields are filled. In it I have a button where when I press it opens a recyclerView, which presents the data of a table. When selecting one of the items in the RecyclerView, I want the object to be passed to the first activity and put the name attribute in an editext. How can I do to keep the data of the form of the first activity ?. This is how I have it but it does not work for me: Activity2:
Proyecto proyectoseleccionado;
proyectoseleccionado= (Proyecto)listaProyecto.get(recyclerViewProyectos.getChildAdapterPosition(v));
//Muestro con un Toast el objeto seleccionado
Toast.makeText(getApplicationContext(),proyectoseleccionado.getNombre(),Toast.LENGTH_SHORT).show();
//Envío el objeto seleccionado a Registro Dietas
Intent intent = new Intent(ListaProyectosActivity.this,RegistroDietasActivity.class);
Bundle bundle= new Bundle();
bundle.putSerializable("proyecto",proyectoseleccionado);
intent.putExtras(bundle);
startActivityForResult(intent,1);
Activity 1 where you receive the object:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bundle objetoRecibido = data.getExtras();
Proyecto proyectoseleccionado=null;
Usuario usuarioseleccionado =null;
if (requestCode ==1 && requestCode==RESULT_OK){
proyectoseleccionado = (Proyecto) objetoRecibido.getSerializable("proyecto");
if (proyectoseleccionado !=null)
txtProyecto.setText(proyectoseleccionado.getNombre().toString());
}
}
The truth is that I do not know if I should do it with the ActivityResult ....