How to pass value using Intent between Activity in Android?

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.


Bundle extras = getIntent().getExtras();

if (extras != null) { 
    String data = intent.getExtras().getString("key").toString();
}

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");

String value = Integer.toString(getIntent().getExtras().getInt("bucketno"));

Tags:

Android