gpt4 book ai didi

android - onActivityResult() 在意外的时间被调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:44:04 25 4
gpt4 key购买 nike

在我的主要 Activity 中,我有:

    Intent settings_intent = new Intent(this, SettingsActivity.class);
settings_intent.putExtra("SomeID", some_int);
startActivityForResult(settings_intent, 1);

然后,在我的 SettingsActivity 中,我有:

@Override
public void onBackPressed() {
super.onBackPressed();
// pass back settings:
Intent data = new Intent();
data.putExtra("SomeThing", some_number);
setResult(200, data);
finish();
}

最后,我在主要 Activity 中覆盖了以下内容:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
makeToast("called");
super.onActivityResult(requestCode, resultCode, data);
}

但是,“调用”toast 在我的“设置” Activity 开始时发生,而不是在它结束时发生。我已经在这上面花了很长时间了。任何帮助表示赞赏。谢谢。

最佳答案

您的设置 Activity 很可能在您的 list 中将其启动模式设置为 singleTask。这会导致在调用 startActivityForResult() 时立即取消响应。

Note that this method should only be used with Intent protocols that are defined to return a result. In other protocols (such as ACTION_MAIN or ACTION_VIEW), you may not get the result when you expect. For example, if the activity you are launching uses the singleTask launch mode, it will not run in your task and thus you will immediately receive a cancel result.

来自 startActivityForResult() documentation

关于android - onActivityResult() 在意外的时间被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8460250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com