-1

I'm trying to pass some data from one activity to another in my android app, however some errors occur when I try to run the code. I'm passing data this way:

 Intent pod= new Intent(ACTION_NAME);
 Bundle extras = new Bundle();
 extras.putString("nume", NUME_VAL);
 extras.putString("prenume", PRENUME_VAL);
 startActivity(pod);

And recive this:

public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     Bundle data = getIntent().getExtras();
     String nume = data.getStringExtra("nume");
     String prenume = data.getStringExtra("prenume");
}
Luiz
  • 13
  • 3
  • @Nilu I'm trying to do the same example but without success, thank you for sharing the link, had lost ... – Luiz Dec 08 '17 at 13:49

3 Answers3

1

Use this

 Intent pod= new Intent(YourActivity.this,OtherActivity.class);
 Bundle extras = new Bundle();
 extras.putString("nume", NUME_VAL);
 extras.putString("prenume", PRENUME_VAL);
 pod.putExtras(extras);
 startActivity(pod);

instead of this

 Intent pod= new Intent(ACTION_NAME);
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
0

Your error is in how you send.

Add after extras.putString("prenume", PRENUME_VAL); the code: pod.putExtras(extras);

And to read on the second activity:

public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     Bundle data = getIntent().getExtras();
     String nume = data.getStringExtra("nume");
     String prenume = data.getStringExtra("prenume");
}
Roberto Pinheiro
  • 1,260
  • 13
  • 30
0
//Sending Data to another activity
Intent intent= new Intent(ACTION_NAME);
intent.putString("nume", NUME_VAL);
intent.putString("prenume", PRENUME_VAL);
startActivity(pod);

//Retrieving Data

Bundle data = getIntent().getExtras();
String nume = data.getStringExtra("nume");
String prenume = data.getStringExtra("prenume");
Ramesh sambu
  • 3,577
  • 2
  • 24
  • 39