Reputation: 3
What i need is what i write at EditText campoempresa and camporesponsavel, i need to show at DiagnosticoActivity, but the program show null or nothing. I'm using a Firebase Database, have another way to do that?
The FirstActivity
@Override
public void onClick(View v) {
String textoequipe = campoequipe.getText().toString();
String textoempresa = campoempresa.getText().toString();
String textosetor = camposetor.getText().toString();
String textoresponsavel = camporesponsavel.getText().toString();
Intent myintent = new Intent(NovoActivity.this, DiagnosticoActivity.class);
Bundle bundle = getIntent().getExtras();
Bundle.getString("campoempresa", textoempresa);
Bundle.getString("camporesponsavel", textoresponsavel);
startActivity(myintent);
if ( !textoequipe.isEmpty()){
if ( !textoempresa.isEmpty()){
if ( !textosetor.isEmpty()){
if ( !textoresponsavel.isEmpty()){
informações = new Informações();
informações.setEquipe( textoequipe );
informações.setEmpresa( textoempresa );
informações.setSetor( textosetor );
informações.setResponsavel( textoresponsavel );
informações.salvar();
The SecondActivity
public class DiagnosticoActivity extends AppCompatActivity {
private Button btbloco;
private Button btanotacoes;
private Button btfotos;
private ImageButton btvnovo;
private ImageButton btvfinalizar;
private TextView EmpresaResponsavel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diagnostico);
EmpresaResponsavel = findViewById(R.id.EmpresaResponsavel);
Intent myintent = getIntent();
String textoempresa = myintent.getStringExtra("campoempresa");
String textoresponsavel = myintent.getStringExtra("camporesponsavel");
EmpresaResponsavel.setText(textoempresa + " - " + textoresponsavel);
Upvotes: 0
Views: 65
Reputation: 781
start activity:
startActivity(new Intent(CurrentActivity.this, AnotherActivity.class).putExtra("campoempresa", textoempresa).putExtra("camporesponsave1", textoresponsave1));
Retrieve value:
Intent i = getIntent();
String v1 = i.getStringExtra("campoempresa");
String v2 = i.getStringExtra("camporesponsave1");
Upvotes: 1
Reputation: 743
you have 2 problems that i can see...
in the first activity use Bundle bundle = getIntent().getExtra("bundle") to retrieve the bundle and then bundle.getString("campoempresa") to get the value of the string...
in the second activity you are not attaching the bundle to the intent...
use myIntent.putExtra(bundle)
create the bundle and start activity:
Intent myIntent = new Intent(this, DiagnosticsoActivity.class);
Bundle bundle = new Bundle();
bundle.putString("campoempresa", textoempresa);
bundle.putString("camporesponsave1", textoresponsave1);
myIntent.putExtra("bundle", bundle);
startActivity(myIntent);
retrieve the bundle in the activity:
Bundle bundle = getIntent().getExtra("bundle");
String textoempresa = bundle.getString("campoempresa");
String textoresponsave1 = bundle.getString("camporesponsave1")
Upvotes: 0