Click here to Skip to main content
Click here to Skip to main content

Passing Values to an Intent

By , 4 Feb 2013
 

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");
} 

License

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

About the Author

DaltonGR
Greece Greece
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 4 Feb 2013
Article Copyright 2013 by DaltonGR
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid