英文:
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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论