How do I get extra data from intent on Android?

后端 未结 16 2268
清歌不尽
清歌不尽 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

    We can do it by simple means:

    In FirstActivity:

    Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
    intent.putExtra("uid", uid.toString());
    intent.putExtra("pwd", pwd.toString());
    startActivity(intent);
    

    In SecondActivity:

        try {
            Intent intent = getIntent();
    
            String uid = intent.getStringExtra("uid");
            String pwd = intent.getStringExtra("pwd");
    
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("getStringExtra_EX", e + "");
        }
    

提交回复
热议问题