Android SetNewPassword Intent 返回 RESULT_FIRST_USER

标签 android android-intent android-activity xamarin mvvmcross

我正在启动 ActionSetNewPassword通过 Intent 操作.返回时我正在关注 OK并运行一些代码或CANCEL和关闭。

这工作正常,但现在我被退回 RESULT_FIRST_USER而不是 OK当我成功处理该 Action 时。

为什么我现在会被传回 RESULT_FIRST_USER ?
该结果代码应该告诉我什么?

编辑

我正在使用 Xamarin 和 MVVMCross 来启动 Activity 。这一切都很好我想知道在什么情况下Android会发回RESULT_FIRST_USER

 Intent actionSetNewPasswordIntent =
       new Intent(DevicePolicyManager.ActionSetNewPassword);

 this.context.StartActivityForResult(
                 actionSetNewPasswordIntent, 
                 20);

在 Activity 中,我正在听这样的返回
if (requestCode == 20)
{
    if (resultCode == Result.Ok)
    {
        if (this.spm.CheckCompliance() != SecurityPolicyCompliance.Compliant)
        {
            // This should not happen as by now we have applied for Device Admin 
            // and sent them to SetNewPassword where they have not cancelled
            this.Finish();
        }
    }
    else if (resultCode == Result.Canceled)
    {
        // User backed away from changing password.
        this.Finish();
    }
}
else
{
    base.OnActivityResult(requestCode, resultCode, data);
}

谢谢

最佳答案

“在您的 SecondActivity 中设置您想要返回给 FirstActivity 的数据。如果您不想返回,请不要设置任何数据。

例如:在 secondActivity 如果你想发回数据:

Intent returnIntent = new Intent();
returnIntent.putExtra("result",result);
setResult(RESULT_OK,returnIntent);
finish();

如果您不想返回数据:
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();

这说我还去了android文档并引用“当一个 Activity 退出时,它可以调用setResult(int)将数据返回给它的父级。它必须始终提供一个结果代码,可以是标准结果RESULT_CANCELED、RESULT_OK或从 RESULT_FIRST_USER 开始的任何自定义值。”

这意味着如果您不使用 setResult 默认为 RESULT_FIRST_USER。

还要注意这一点:“如果子 Activity 因任何原因(例如崩溃)失败,则父 Activity 将收到代码为 RESULT_CANCELED 的结果”
希望这对您有所帮助。

关于Android SetNewPassword Intent 返回 RESULT_FIRST_USER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25080967/

相关文章:

java - 安卓 : Using Broadcasting Receiver

android - 如何杀死我自己的 Activity - 艰难的方式

android - 更改 TextView 文本

android - 获取唤醒我的 Activity 的 Intent

java - Android将字节数组转换为文件并将文件保存在SD卡中

android - ListView 选择开始一个新的 Activity

android - 以编程方式定义默认 Activity (当应用程序启动时)

java - 尝试在 Android 上扩展和使用 Activity 时出错

android - 钛备份 - 坚持搜索应用程序数据

java - RejectedExecutionException 的原因是什么?