Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing data between activities in Android

Tags:

android

How do you pass data between activities in an Android application?

like image 748
yokks Avatar asked Jun 03 '10 10:06

yokks


People also ask

What way is used to pass data between activities in android?

We can send the data using putExtra() method from one activity and get the data from the second activity using the getStringExtra() method.

How do you pass data between two activities?

To pass data between two activities, you will need to use the Intent class via which you are starting the Activity and just before startActivity for ActivityB, you can populate it with data via the Extra objects. In your case, it will be the content of the editText.

How can I transfer data from one app to another in Android?

Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.


1 Answers

in your current activity, create an intent

Intent i = new Intent(getApplicationContext(), ActivityB.class); i.putExtra(key, value); startActivity(i); 

then in the other activity, retrieve those values.

Bundle extras = getIntent().getExtras();  if(extras !=null) {     String value = extras.getString(key); } 
like image 146
Pentium10 Avatar answered Sep 18 '22 09:09

Pentium10