jeudi 26 juin 2014

adding contacts with intent in for-each loop


Vote count:

0




I ran into one problem. I have to add users in the for-each loop through intent.



for (User u : checkedUsers) {
usersToCheck.add(u);
Log.e(TAG,
"Adding users to usersToCheck: "
+ usersToCheck.size());
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME,
u.getName());
intent.putExtra(
INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, true);
startActivityForResult(intent, ADD_CONTACT);
}


Then in onActivityResult I want to get contacts which the user added/edited. Unfortunately still get the URI only the last user (I understand the reasons why this is so, because I cycle over INTENT times and never returns to the Activity, so onActivityResult run only once).



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data == null) {
Log.e(TAG, "DATA NULL");
}
Log.d(TAG, "INSIDE ON RESULT");
if (requestCode == ADD_CONTACT) {
if (resultCode == RESULT_OK) {
// HERE I GET URI FOR LAST CHECKED USER ONLY
Uri contactData = data.getData();
} else {
Log.e(TAG, "RESULT NOT OK!");
}
}
// usersToCheck.clear();
}
}


Could anyone advise me how this could be synchronized?



asked 37 secs ago






Aucun commentaire:

Enregistrer un commentaire