Android Intent:始终获得resultCode = 0
创始人
2024-08-14 06:00:07
0

要始终获得 resultCode = 0,可以通过以下方法:

  1. 设置 startActivityForResult 方法的 resultCode 参数为 0,确保在启动 Activity 时始终设置 resultCode 为 0。
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivityForResult(intent, 0);
  1. 在被启动的 Activity 中,设置 setResult 方法的 resultCode 参数为 0,确保在返回结果时始终设置 resultCode 为 0。
Intent resultIntent = new Intent();
setResult(0, resultIntent);
finish();
  1. 在启动 Activity 的地方,使用 onActivityResult 方法检查 resultCode 的值是否为 0。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 0) {
        if (resultCode == 0) {
            // 处理 resultCode 为 0 的情况
        } else {
            // 处理其他 resultCode 的情况
        }
    }
}

通过以上方法,可以确保始终获得 resultCode = 0。

相关内容

热门资讯

开挂透视!智星菠萝有挂吗,微乐... 开挂透视!智星菠萝有挂吗,微乐自建房脚本最新版本更新内容,教程书教程(有人有挂)-哔哩哔哩进入游戏-...
普及透视!wepokerplu... 普及透视!wepokerplus透视脚本免费,微信小程序微乐破解器,要领教程(有挂工具)-哔哩哔哩1...
解谜透视!wepoker开辅助... 解谜透视!wepoker开辅助能查到吗,微信微乐小程序有窍门吗,举措教程(有挂细节)-哔哩哔哩1)w...
推荐透视!佛手在线是不是有挂,... 推荐透视!佛手在线是不是有挂,万能透视辅助器免费版,窍门教程(竟然有挂)-哔哩哔哩1、玩家可以在佛手...
总结透视!wpk辅助器是真的吗... 总结透视!wpk辅助器是真的吗,微乐贵阳麻将辅助,窍门教程(有挂猫腻)-哔哩哔哩1、wpk辅助器是真...
解谜透视!poker worl... 解谜透视!poker world辅助,微乐多乐跑作弊,练习教程(有挂方略)-哔哩哔哩1、poker ...
了解透视!wpk插件,微乐四川... 了解透视!wpk插件,微乐四川小程序修改器,演示教程(了解有挂)-哔哩哔哩1、操作简单,无需wpk插...
开挂透视!hh poker软件... 开挂透视!hh poker软件,微乐陕西小程序破解器,方案教程(证实有挂)-哔哩哔哩1、金币登录送、...
关于透视!aapoker透视脚... 关于透视!aapoker透视脚本下载,微信小程序游戏破解器,积累教程(有人有挂)-哔哩哔哩1、完成a...
解密透视!wepoker怎么拿... 解密透视!wepoker怎么拿到好牌,微乐小程序自建房辅助下载,模块教程(有挂教程)-哔哩哔哩wep...