Search code examples
androidandroid-intentcontactsandroid-4.0-ice-cream-sandwich

Android 4 startActivityForResult with Intent.ACTION_EDIT always returns resultcode RESULT_CANCELED


This problem occurs with android version 4.0.3. I am adding contacts with a custom RawContacts.ACCOUNT_TYPE using the Android Contacts 2.0 API. As a second step I want to use Intent.ACTION_EDIT to edit those contacts using the following code:

Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setData(contactUri);
startActivityForResult(intent, EDIT_CONTACT_RESULT);

The Intent is opening up the android built in edit contact activity. But when I press done, it is forwarding me to a contact view activity of the currently edited contact. If I then hit the back button, I get forwarded back to my application. The Problem is that onActivityResult(); always returns RESULT_CANCELED as a result code. Any ideas how to solve this problem?

Thanks.


Solution

  • This happens even on "stock Android" (JB, Galaxy Nexus). It seems the only way around it is to ignore the result code and to reread the contact again regardless of it (note that the Intent data will also be null, so you'd have to the contact Uri you had used when opening the Edit Activity).