Click here to Skip to main content
15,881,852 members
Articles / Mobile Apps / Android
Tip/Trick

Passing Values to an Intent

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
4 Feb 2013CPOL 9K   2  
Tip on how to pass a value to an intent

Introduction

It's the simplest thing. An Android developer will need some time passing a value from one intent to another, making intents aware of each other.

Using the Code

Java
Intent myIntent = new Intent(this, mySecondActivity.class);
myIntent.putExtra("KeyName", keyValue);
startActivity(myIntent);

Points of Interest

You can pass whatever value you want to the other activity. Using the below code, you can retrieve the values given from the previous activity. 

Java
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("KeyName");
} 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
DASoftware
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --