65.9K
CodeProject is changing. Read more.
Home

Passing Values to an Intent

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (2 votes)

Feb 4, 2013

CPOL
viewsIcon

9190

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

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. 

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