后退按钮没有返回到previous活动 [英] back button not returning to previous activity

查看:171
本文介绍了后退按钮没有返回到previous活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的小测试应用程序是显示所有联系人ListActivity。当用户点击一个,它打开了人ACTION_EDIT活动。这工作得很好。当用户点击返回或以其他方式编辑完毕,主打人物排行榜活动开始,而不是回到我的活动。

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?

下面是我的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);
  }
}

注意的onActivityResult不会被调用。同时,请意识到,我有过接触的编辑code无控制 - 这是与Android提供的人的应用程序的一部分。
谢谢你。

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.

推荐答案

我申请到Android这个错误。有人看了一下,回答说有一个未公开的解决方法。从错误报告:

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

未公开的解决方法是调用putExtra(finishActivityOnSaveCompleted,真正的);在ACTION_EDIT意向。结果
  然而,由于这是无证的,我不知道哪个版本的Andr​​oid(S)将使用它。

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.

我想它和它的作品为Android的版本,我使用的是:4.1.2。请参见问题39262 获取更多信息。

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

这篇关于后退按钮没有返回到previous活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆