I’m new to android studio, I came across this multiple contact picker and I want to get phone numbers in 1st activity and in the 2nd activity send messages to those selected numbers.
In my first activity I have –
new MultiContactPicker.Builder(MainActivity.this) //Activity/fragment context
.theme(R.style.MyCustomPickerTheme) //Optional - default: MultiContactPicker.Azure
.hideScrollbar(false) //Optional - default: false
.showTrack(true) //Optional - default: true
.searchIconColor(Color.WHITE) //Option - default: White
.setChoiceMode(MultiContactPicker.CHOICE_MODE_MULTIPLE) //Optional - default: CHOICE_MODE_MULTIPLE
.handleColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary)) //Optional - default: Azure Blue
.bubbleColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary)) //Optional - default: Azure Blue
.bubbleTextColor(Color.WHITE) //Optional - default: White
.setTitleText("Select Contacts") //Optional - default: Select Contacts
.setSelectedContacts("10", "5" / myList) //Optional - will pre-select contacts of your choice. String... or List<ContactResult>
.setLoadingType(MultiContactPicker.LOAD_ASYNC) //Optional - default LOAD_ASYNC (wait till all loaded vs stream results)
.limitToColumn(LimitColumn.NONE) //Optional - default NONE (Include phone + email, limiting to one can improve loading time)
.setActivityAnimations(android.R.anim.fade_in, android.R.anim.fade_out,
android.R.anim.fade_in,
android.R.anim.fade_out) //Optional - default: No animation overrides
.showPickerForResult(CONTACT_PICKER_REQUEST);
The numbers get stored in results which is also in 1st activity –
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CONTACT_PICKER_REQUEST){
if(resultCode == RESULT_OK) {
List<ContactResult> results = MultiContactPicker.obtainResult(data);
Log.d("MyTag", results.get(0).getDisplayName());
} else if(resultCode == RESULT_CANCELED){
System.out.println("User closed the picker without selecting items.");
}
}
}
I called the results in 2nd activity –
List<ContactResult> results = new ArrayList<>();
But when I print the output, it doesn’t give any. How can I get it right. Thanks in advance.
2
Answers
You can set up intents when you are starting a new activity. Intents are a way to pass values from your current activity to the next and I’d suggest you learn the basics uses for them. Here’s official documentation you can check out: https://developer.android.com/guide/components/intents-filters
When you start the other activity you can code the Intent like this:
On the SecondActivity.class you will get can then assign your value to a variable:
First activity sent your data:-
// if you want to send on selected position data than pass position in place of zero (0).
// if you want to send the all the list in second activity using intent than
Second activity get your data:-
// retrive selected position data
// retrive result list from intent
hope this answer will helpful for you…