You are on page 1of 3

Ngy 7 thng 6 nm 2014 Sending multiple data with intent in android - Stack Overflow

http://stackoverflow.com/questions/21332178/sending-multiple-data-with-intent-in-android 1/3
Take the 2-minute tour
Ruchika
20 6
I am trying to receive two inputs in EditTexts in android in one activity (activity1). the two inputs are
dimensions of a table which i am dynamically creting in another activity (activity2). I tried using Bundles
as well as simple intents. i am recieving one dimension but unable to recieve the other one. the second
dimension automatically acquires the value of first dimension.
How do I send and recieve more than one value in android. please help.
My first activity is as follows
public final static String EXTRA_MESSAGE = "abc";
public final static String EXTRA_MESSAGE2 = "abc";
Intent intent = new Intent( c , CreateTimeTable.class);
Bundle bun = new Bundle();
EditText editText = (EditText) findViewById(R.id.nlec);
EditText editText2 = (EditText) findViewById(R.id.nday);
String message = editText.getText().toString();
String message2 = editText2.getText().toString();
bun.putString(EXTRA_MESSAGE, message);
bun.putString(EXTRA_MESSAGE2, message2);
intent.putExtras(bun);
startActivity(intent);
The second activity is
setContentView(R.layout.activity_create_time_table);
int j;
Intent intent = getIntent();
Bundle bun = this.getIntent().getExtras();
String message = bun.getString(NewTT.EXTRA_MESSAGE);
String message2 = bun.getString(NewTT.EXTRA_MESSAGE2);
int lec = Integer.parseInt(message);
int day = Integer.parseInt(message2);
the variable lec acquires same value as day no matter what the input is
android android-intent
edited Jan 24 at 12:32 asked Jan 24 at 12:02
closed as off-topic by Selvin, laalto, marqss, Aniket Thakur, Maxime
Lorant Jan 25 at 9:10
This question appears to be off-topic. The users who voted to close gave these specific reasons:
"This question appears to be off-topic because it lacks sufficient information to diagnose the problem.
Describe your problem in more detail or include a minimal example in the question itself." Selvin, Maxime
Lorant
"This question was caused by a problem that can no longer be reproduced or a simple typographical
error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help
future readers. This can often be avoided by identifying and closely inspecting the shortest program
necessary to reproduce the problem before posting." laalto, marqss, Aniket Thakur
If this question can be reworded to fit the rules in the help center, please edit the question.
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no
registration required.
Sending multiple data with intent in android [closed]
sign up

log in

tour

help

careers 2.0

Ngy 7 thng 6 nm 2014 Sending multiple data with intent in android - Stack Overflow
http://stackoverflow.com/questions/21332178/sending-multiple-data-with-intent-in-android 2/3
4 Answers
laalto
46.4k 14 60 97
Digvesh Patel
2,560 1 23
Anil Bhatiya
2,211 2 10 28
1 post ur code... Anil Bhatiya Jan 24 at 12:03
dito .. post code LeMoN.xaH Jan 24 at 12:03
What you have tried ???? Karan Mavadhiya Jan 24 at 12:04
What exactly you want to do. Post your code,,, InnocentKiller Jan 24 at 12:05
public final static String EXTRA_MESSAGE = "abc";
public final static String EXTRA_MESSAGE2 = "abc";
the variable lec acquires same value as day no matter what the input is
The keys are the same so the values are the same. Make the keys different.
answered Jan 24 at 12:34
Thank you so much. :) Ruchika Jan 24 at 13:03
Intent myIntent = new Intent(mycurentActivity.this, secondActivity.class);
myIntent.putExtra("key", myEditText1.Text.toString());
myIntent.putExtra("key1", myEditText2.Text.toString());
myIntent.putExtra("key2", myEditText3.Text.toString());
startActivity(myIntent);
String text = myIntent.getStringExtra("key1");
String text1 = myIntent.getStringExtra("key2");
String text3 = myIntent.getStringExtra("key");
answered Jan 24 at 12:06
Intent intent= new Intent(YourActivity.this, SecondActivity.class);
intent.putExtra("key1", valuetopass_1);
intent.putExtra("key2", valuetopass_2);
startActivity(intent);
// Get values in second activity
SecondActivity.java
Intent in = getIntent();
String value1 = in.getStringExtra("key1");
String value2 = in.getStringExtra("key2");
answered Jan 24 at 12:07
While sending intent:
intent.putExtra("YOUR-KEY_1", "data_here");
intent.putExtra("YOUR-KEY_2", "data_here");
While receiving intent:
add comment
add comment
add comment
add comment
Ngy 7 thng 6 nm 2014 Sending multiple data with intent in android - Stack Overflow
http://stackoverflow.com/questions/21332178/sending-multiple-data-with-intent-in-android 3/3
Anuj Sharma
76 9
if(getIntents()!= null){
String data1 = getIntents().getExtras().getString("YOUR-KEY_1");
String data2 = getIntents().getExtras().getString("YOUR-KEY_2");
}
That's it! :)
answered Jan 24 at 12:10
Not the answer you're looking for? Browse other questions tagged android
android-intent or ask your own question.
add comment

You might also like