-1
Good afternoon guys, I have a job to deliver done in Android Studio, I was trying to send Strings by intents, my teacher said that the correct way would be using startActivityForResult() and Onactivity(), but it seems that the Strings are not being sent, I tried to change it in various ways. Can you help me?
Sending Activity Code
btArmazenaDisco.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
estilMusica = EstiloMusical.getText().toString();
alb = album.getText().toString();
artist = artista.getText().toString();
quantmusic = quantmusica.getText().toString();
// enviando os itens
Intent intentEnviador = new Intent(CriarDiscoActivity.this,Activity_Pastas.class);
Bundle informacao = new Bundle();
informacao.putString("addestilMusica",estilMusica);
informacao.putString("addAlbum",alb);
informacao.putString("addArtista",artist);
informacao.putString("addQuantiMusica",quantmusic);
intentEnviador.putExtras(informacao);
setResult(RESULT_OK,intentEnviador);
startActivityForResult(intentEnviador,Constante_Activity_Pastas);
}
Code Activity Receiver
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==CriarDiscoActivity.RESULT_OK && requestCode== CriarDiscoActivity.Constante_Activity_Pastas) {
Bundle bundle = data.getExtras();
if(bundle!= null) {
estiloMusica = bundle.getString("addestilMusica");
Album = bundle.getString("addAlbum");
Artista = bundle.getString("addArtista");
QuantMusica = bundle.getString("addQuantiMusica");
//Testando para ver se foi enviado
test.setText(estiloMusica);
Toast.makeText(this, estiloMusica, Toast.LENGTH_SHORT).show();
//
musicas.add(new Musica(estiloMusica, Album, Artista, QuantMusica, 0));
}
}
}
Put code as formatted text here, don’t use images to share code
– Rafael Tavares
Okay, I put the code, thank you for warning.
– user190650