2
Good morning, everyone,
I have the following situation:
I have 4 screens (Activity), they are: Mainactivity, Disiplinaactivity, Avaliacaoactivity and Resultfinalactivity.
The point is, the data collected from the Disiplinaactivity and Avaliacaoactivity screens is returned to Mainactivity and then sent to Resultadofinalactivity.
My question is: how do I send this data through key, value? So far I have this code, where I get the values, but I don’t know how to send them to the final screen.
Has anyone ever taken something like this or can give me a light?
Thanks
public void proximaTela(View v) {
Intent enviarDados = null;
switch (v.getId()) {
case R.id.btnDisciplina:
enviarDados = new Intent(this, DisciplinaActivity.class);
enviarDados.putExtra("disciplina", disciplina);
startActivityForResult(enviarDados, Constantes.REQUEST_CODE_DADOS_DISCIPLINA);
break;
case R.id.btnAvalicao1:
enviarDados = new Intent(this, AvaliacaoActivity.class);
enviarDados.putExtra("avaliacao1", disciplina);
startActivityForResult(enviarDados, Constantes.REQUEST_CODE_DADOS_AVALIACAO);
break;
case R.id.btnAvalicao2:
enviarDados = new Intent(this, AvaliacaoActivity.class);
enviarDados.putExtra("avaliacao2", disciplina);
startActivityForResult(enviarDados, Constantes.REQUEST_CODE_DADOS_AVALIACAO2);
break;
case R.id.telaResultado:
enviarDados = new Intent(this, ResultadoActivity.class);
break;
default:
Toast.makeText(this, "Problema ao enviar ou receber dados!", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
if (requestCode == Constantes.REQUEST_CODE_DADOS_DISCIPLINA){
Bundle params = data.getExtras();
String disciplina = params.getString("nomeDisciplina");
String professor = params.getString("nomeProfessor");
}else if (requestCode == Constantes.REQUEST_CODE_DADOS_AVALIACAO){
Bundle params = data.getExtras();
String avaliacao1 = params.getString("tituloAvl1");
Double nota1 = params.getDouble("notaAvl1");
}else if (requestCode == Constantes.REQUEST_CODE_DADOS_AVALIACAO2){
Bundle params = data.getExtras();
String avalicao2 = params.getString("tituloAvl2");
Double nota2 = params.getDouble("notaAvl2");
}
}
}
Save Screen Button Disciplinaactivity
public void btnSalvar(View v) { Intent Intent = new Intent(this, Mainactivity.class); Intent.putExtra("nomenDiscipline", editnomeDisciplina.gettext().toString()); Intent.putExtra("nomeProfessor", editNomeProfessor.gettext().toString()); startActivity(Intent); setResult(RESULT_OK,Intent); Finish(); }
I didn’t understand this
switch
. It looks like it has a button for 4 screens. Are they unique data? Just one subject, just one teacher? Or are there several disciplines and various other data?– Gaspar
Exactly, I have 4 screens and this switch I used to redirect through the Activitys ID. For example, the Disciplinaactivity screen has the "Iscipline" and "Ofessor" fields, by clicking for example on the "Save" button it returns to Mainactivity already with the data in an Intent, right? So it goes to the screen of Avaliacaoactivity. After all, I have data of the two Activitys in Mainactivity and I need to send it to the final result screen using Intent.. I don’t know if I was clear, rsrsr
– Maicon Queiroz
I still don’t understand, at the end of
onClick
from the save button you put extras in the Intent and calls thefinish()
?– Gaspar
I put the save button code
– Maicon Queiroz
So it would be this flow:
MainActivity.class > DisciplinaActivity.class > MainActivity.class > AvaliacaoActivity.class > MainActivity.class
?– Gaspar