Receive data from 4 activities in a single activity

0

I have 4 activities in which I enter data and I want to receive the same data in a single activity .

First data logging activity:

Intent Register = new Intent(this,Window_Configuracion.class);
etConstanteK = (EditText)findViewById(R.id.txtConstanteK);
etDC = (EditText)findViewById(R.id.txtDC);

Register.putExtra("K_To_Objetivo",etConstanteK.getText().toString() );
Register.putExtra("DC_To_Objetivo",etDC.getText().toString() );

Toast toastconfirmed = Toast.makeText(getApplicationContext(),
"Se han registrado exitosamente las variables", Toast.LENGTH_SHORT);
toastconfirmed.show();

startActivity(Register);

Second data logging activity:

Intent Register = new Intent(this, Window_Configuracion.class);
etHP = (EditText)findViewById(R.id.txtHP);
etDEG = (EditText)findViewById(R.id.txtDEG);

Register.putExtra("HP_To_Objetivo",etHP.getText().toString() );
Register.putExtra("DEG_To_Objetivo",etDEG.getText().toString() );

Toast toastconfirmed = Toast.makeText(getApplicationContext(),
"Se han registrado exitosamente las variables", Toast.LENGTH_SHORT);
 toastconfirmed.show();

 startActivity(Register);

Third data logging activity:

Intent Register = new Intent(this, Window_Configuracion.class);
etGravedad = (EditText)findViewById(R.id.txtGravedad);

Register.putExtra("Gravedad_To_Objetivo",etGravedad.getText().toString() );

Toast toastconfirmed = Toast.makeText(getApplicationContext(),
      "Se ha registrado exitosamente la variable", Toast.LENGTH_SHORT);
toastconfirmed.show();
startActivity(Register);

Fourth data logging activity:

Intent Register = new Intent(this, Window_Configuracion.class);
etMasa = (EditText)findViewById(R.id.txtMasa);

Register.putExtra("Masa_To_Objetivo",etMasa.getText().toString() );

Toast toastconfirmed = Toast.makeText(getApplicationContext(),
      "Se ha registrado exitosamente la variable", Toast.LENGTH_SHORT);
toastconfirmed.show();

startActivity(Register);

Activity where I need to get all the data:

Bundle datos = getIntent().getExtras();
txtConstanteK = datos.getString("K_To_Objetivo");
txtDC = datos.getString("DC_To_Objetivo");
txtGravedad= datos.getString("Gravedad_To_Objetivo");
txtHP = datos.getString("HP_To_Objetivo");
txtDEG = datos.getString("DEG_To_Objetivo");
txtMasa = datos.getString("Masa_To_Objetivo");

I use the bundle method but it always marks me error.

    
asked by Alonso Contreras 18.04.2018 в 19:43
source

1 answer

1

Take the following points into account:

  • Only the data you send in a Intent are those that will receive the Activity you wish to open.
  • If you want to receive all the values, you should send them in a Intent .

Regarding the error when receiving the data, it can be generated when receiving null values, for this you can add a default parameter that would be assigned in case of not receiving value: getString(<key> , <valor default>) .

You can make this change by assigning an empty string as a default value to avoid possible problems:

Bundle datos = getIntent().getExtras();
txtConstanteK = datos.getString("K_To_Objetivo", "");
txtDC = datos.getString("DC_To_Objetivo", "");
txtGravedad= datos.getString("Gravedad_To_Objetivo", "");
txtHP = datos.getString("HP_To_Objetivo", "");
txtDEG = datos.getString("DEG_To_Objetivo", "");
txtMasa = datos.getString("Masa_To_Objetivo", "");
    
answered by 18.04.2018 в 23:03