Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get extra data from intent on Android?

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("id", user.getUserAccountId()+""); i.putExtra("name", user.getUserFullName()); context.startActivity(i); 
like image 566
Adham Avatar asked Nov 20 '10 16:11

Adham


People also ask

How do I get extra string from Intent?

Intent intent = getIntent(); String user = intent. getStringExtra("uid"); String pass = intent. getStringExtra("pwd"); We use generally two method in intent to send the value and to get the value.

What is Intent extras in Android?

We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.

What is put extra in Intent?

Using putExtra() and getExtras() in android Intents are asynchronous messages which allow Android components to request functionality from other components of the Android system. For example an Activity can send an Intents to the Android system which starts another Activity .

How do I transfer data from one Intent to another?

Using Intents This example demonstrate about How to send data from one activity to another in Android using intent. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

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"); 
like image 133
Malcolm Avatar answered Sep 24 '22 21:09

Malcolm