How do I get extra data from intent on Android?

后端 未结 16 2324
清歌不尽
清歌不尽 2020-11-21 11:01

How can I send data from one activity (intent) to another?

I use this code to send data:

Intent i=new Intent(context,SendMessage.class);
i.putExtra(\         


        
16条回答
  •  無奈伤痛
    2020-11-21 11:53

    //  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
    

提交回复
热议问题