I got list of checked contacts.However, i need to pass these selected contacts to another activity and display in edit Text.Please help.Thanks
Asked
Active
Viewed 1,010 times
2 Answers
1
You have a few solutions...
- You can use static fields in your Java classes
- You can pack the data into Intents via Intent.putExtra
Option (1) is probably going to be the easiest and quickest if you are trying to send data between your own activities. Option (2) is what you must do if you wish to send data to Activities of another applications.
I suggest you read these Q&A first though as some cover this question in more depth...
Passing data of a non-primitive type between activities in android

Community
- 1
- 1

Andrew White
- 52,720
- 19
- 113
- 137
0
You have to use an Intent to do so.
Example, to pass the data to an activity already running:
public void sendToActivity(Object data){
Intent i = new Intent("SEND_DATA");
i.putExtra("data", this.catchReports.get(data));
sendBroadcast(i);
}
Then, you have to setup a listener in your receiving activity to catch the Broadcasted signal:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
// Sets the View of the Activity
setContentView(R.layout.activity_layout);
registerReceiver(new CustomReceiver(this), new IntentFilter("SEND_DATA"));
}
With the following customreceiver:
public class CustomReceiver extends BroadcastReceiver {
private MyActivity activity;
public ReceiverEvent(MyActivity activity) {
this.activity = activity;
}
public void onReceive(Context context, Intent i) {
this.activity.doWhateverWithYourData(i.getParcelableExtra("newEvent"));
}
}
Note that if you want to transport Objects other than integers, floats and strings, you have to make them Parcelable.

nbarraille
- 9,926
- 14
- 65
- 92
-
Whoa, why are you using broadcasts to send data to an Activity? Why not just send the info in the intent and have the intent launch the desired Activity? – Andrew White Dec 09 '10 at 14:05
-
This is for passing the data to an activity which is already running, not to start a new one with the data, in which case you can just do a startActivity with the intent and retrieve it in the onCreate() with Bundle.getIntent(), as explained in the first link of your post. – nbarraille Dec 09 '10 at 14:11