How to read data from Intent on Android

Asked 2 years ago, Updated 2 years ago, 103 views

I sent data to Intent from one activity to another.

Intent i=new Intent(context,SendMessage.class);
i.putExtra("id", user.getUserAccountId()+"");
i.putExtra("name", user.getUserFullName());
context.startActivity(i);

I like what I sent, but how do I receive it??

android android-intent

2022-09-22 22:34

1 Answers

You can use the getIntent() method in the activity of receiving data.

Intent intent = getIntent();

In the example you gave me, I sent it with ID and name

intent.getStringExtra(string name) where putExtra(name, data); If you put the string corresponding to the first factor of putExtra together, you can get the value you put in the second factor.

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


2022-09-22 22:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.