I'm able to pass the object by Activity's
using putExtra
and returning on the other screen with getSerializableExtra
.
I already created fk id_usuario
in the products table for the id_user
field of the users table.
My question now is:
How do I insert my product into the linked products table with the user id of the users table?
How do I insert this product? Where do I pass the user ID I got in Activity to be inserted into it? Usage in contentValues
? In insert repository method? If you have an example it would help a lot!
public ContentValues contentValues(Reporte reporte) {
ContentValues values = new ContentValues();
values.put("id_user", reporte.getIdUsuario());
values.put("tipo", reporte.getTipoReporte());
values.put("descricao", reporte.getDescricaoReporte());
values.put("status", reporte.getStatusReporte());
values.put("data", reporte.getDataAbertura());
values.put("hora", reporte.getHoraAbertura());
values.put("latitude", reporte.getLatitude());
values.put("longitude", reporte.getLongitude());
values.put("endereco", reporte.getEndereco());
return values;
}
public long insertReporte(Reporte novoReporte) {
long id = 0;
try {
ContentValues values = contentValues(novoReporte);
id = db.insert("reportes", null, values);
} catch (Exception e) {
Log.e("Erro: ", e.getMessage());
}
return id;
}