How do I get extra data from intent on Android? How do I get extra data from intent on Android? android android

How do I get extra data from intent on Android?


First, get the intent which has started your activity using the getIntent() method:

Intent intent = getIntent();

If your extra data is represented as strings, then you can use intent.getStringExtra(String name) method. In your case:

String id = intent.getStringExtra("id");String name = intent.getStringExtra("name");


In the receiving activity

Bundle extras = getIntent().getExtras(); String userName;if (extras != null) {    userName = extras.getString("name");    // and get whatever type user account id is}


//  How to send value using intent from one class to another class//  class A(which will send data)    Intent theIntent = new Intent(this, B.class);    theIntent.putExtra("name", john);    startActivity(theIntent);//  How to get these values in another class//  Class B    Intent i= getIntent();    i.getStringExtra("name");//  if you log here i than you will get the value of i i.e. john