I want to pass the value of the position in one activity class to another...
My code is as follows:
protected void onListItemClick(ListView listView,
You can use :
In first activity ( MainActivity page )
Intent i = new Intent(MainActivity.this,SecondActivity.class);
i.putExtra("YourValueKey", yourData.getText().toString());
then you can get it from your second activity by :
In second activity ( SecondActivity page )
Intent intent = getIntent();
String YourtransferredData = intent.getExtras().getString("YourValueKey");
From the First Activity
Intent i=new Intent(getApplicationContext(),BookPractionerAppoinment.class);
i.putExtra("prac","test");
startActivity(i);
Getting values in Second ACT Activity
String prac=getIntent().getStringExtra("prac);
For Serialized objects:
Passing
Intent i=new Intent(getApplicationContext(),BookPractionerAppoinment.class);
i.putExtra("prac",pract);
startActivity(i);
Getting
pract= (Payload) getIntent().getSerializableExtra("prac");
String value = Integer.toString(getIntent().getExtras().getInt("bucketno"));
Use:
String value = getIntent().getExtras().get("key").toString();
getIntent().getExtras()
will give you Boundle. get()
method can be used to fetch the values.
In addition who has different sittuation
double userDMH = Util.getInstance(TakeInfoOne.this).calculateBMH(userGender, kg, talll, currentAge, activityy);
Intent intentTogeneral = new Intent(TakeInfoOne.this, TakeInfoTwo.class);
intentTogeneral.putExtra("user_current_age",userDMH );
startActivity(intentTogeneral);
If you put other primitives like double , boolean , int just dont forget to type correct format while geting the value in secont Activity
Bundle extras = getIntent().getExtras();
if (extras != null) {
double value = extras.getDouble("user_current_age");
txt_metabolism.setText(""+value);
}
Here with extras.getDouble()
type your concerned value type like
extras.getInt("user_current_age");
extras.getBoolean("user_current_age");
extras.getString("user_current_age");
Replace this,
String value = getIntent().getExtras().getString("bucketno");
with
int value = getIntent().getExtras().getInt("bucketno");
You are trying to pass int value but retrieving String Data. That's why you are getting the nullpointerException.