应用在运行onActivityResult后进入后台。

huangapple go评论81阅读模式
英文:

App goes to the background after running onActivityResult

问题

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case RC_SIGN_IN:
            if (resultCode == RESULT_CANCELED) {
                finish();
            } else {
                System.out.println("Here" + Integer.toString(requestCode) + Integer.toString(resultCode));
            }
        case RC_START_APP:
            if (resultCode == RESULT_LOGOUT) {
                signout();
            } else {
                finish();
            }
    }
}
英文:

I am using FirebaseUI to log in to my app. On returning from the login activity, the following onActivityResult-override prints Here1-1, which is as expected. However, immediately after, the activity finishes, which is not what I want. I feel really lost, does anyone have any idea what could be happening?

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode,resultCode,data);
    switch (requestCode) {
        case RC_SIGN_IN:
            if (resultCode == RESULT_CANCELED) {
                finish();
            } else {
                System.out.println("Here" + Integer.toString(requestCode) + Integer.toString(resultCode));
            }
        case RC_START_APP:
            if (resultCode == RESULT_LOGOUT) {
                signout();
            } else {
                finish();
            }
    }
}

答案1

得分: 2

你的案例需要添加break语句来停止执行,以防止它们继续执行到下一个案例。你的活动实际上是因为在第二个RC_START_APP案例中执行了finish()而结束的。

    switch (requestCode) {
        case RC_SIGN_IN:
            if (resultCode == RESULT_CANCELED) {
                finish();
            } else {
                System.out.println("Here" + Integer.toString(requestCode) + Integer.toString(resultCode));
            }
            break;  // 在这里添加break
        case RC_START_APP:
            if (resultCode == RESULT_LOGOUT) {
                signout();
            } else {
                finish();
            }
            break;  // 在这里添加break
    }
英文:

Your cases need a break to stop execution so they don't fall through to the next case. Your activity is actually just finishing due to executing the finish() in the second RC_START_APP case.

    switch (requestCode) {
        case RC_SIGN_IN:
            if (resultCode == RESULT_CANCELED) {
                finish();
            } else {
                System.out.println("Here" + Integer.toString(requestCode) + Integer.toString(resultCode));
            }
            break;  // add this break
        case RC_START_APP:
            if (resultCode == RESULT_LOGOUT) {
                signout();
            } else {
                finish();
            }
            break;  // add this break
    }

huangapple
  • 本文由 发表于 2020年9月20日 01:33:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63971582.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定