Question

My small test app is a ListActivity which displays all the contacts. When the user clicks one, it opens the "people" ACTION_EDIT activity. This works fine. When the user clicks "back" or finishes editing in some other way, the main "People" list activity starts, rather than returning to my activity.

Why is this happening?

Here's my code:

public class ReadContact extends ListActivity implements OnItemClickListener
{
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
      ...
  }

  @Override
  public void onItemClick (AdapterView<?> parent, View view, int position, long id) 
  {
    Cursor cur = ((SimpleCursorAdapter)parent.getAdapter()).getCursor();
    cur.moveToPosition (position);
    String key = cur.getString (2);
    System.out.println ("clicked " + key);

    // make intent to edit contact
    Intent intent = new Intent (Intent.ACTION_EDIT);
    intent.setData (Uri.parse (ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + key));
    startActivityForResult (intent, 2);
  }

  @Override
  protected void onActivityResult (int requestCode, int resultCode, Intent data)
  {
    System.out.println ("request " + requestCode + ", result " + resultCode);
  }
}

Note that onActivityResult is never called. Also please realize that I have no control over the contact editing code - that's part of the "people" app supplied with android. Thanks.

Was it helpful?

Solution

I filed a bug to android about this. Someone looked at it and responded that there is an undocumented workaround. From the bug report:

The undocumented workaround is to call putExtra("finishActivityOnSaveCompleted", true); on the ACTION_EDIT Intent.
However, as this is undocumented, I have no idea which Android version(s) will use it.

I tried it and it works for the version of Android I'm using: 4.1.2. See issue 39262 for more info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top