gpt4 book ai didi

android - onActivityResult 和 FLAG_ACTIVITY_NEW_TASK : workaround?

转载 作者:行者123 更新时间:2023-12-03 17:32:37 27 4
gpt4 key购买 nike

这是我的场景:我有一系列 Activity .我对那些 Activity 设置了超时这将断开用户的连接,以防它暂时处于非 Activity 状态。但我想将用户重定向到最后一个屏幕,以防他登录

当我断开用户连接时,我正在调用:

public void restartFromLoginActivity(boolean saveCurrentState, String previousLoggedUserId) {
Activity currentActivity = getCurrentActivity();
Intent intent = new Intent(CERHISApplication.this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

if(saveCurrentState && currentActivity != null){
Bundle extras = new Bundle();
extras.putString(ApplicationController.KEY_PREVIOUSLY_LOGGED_USER_ID, previousLoggedUserId);
intent.putExtras(extras);
currentActivity.startActivityForResult(intent, ApplicationController.RC_LOGIN);
}
else
startActivity(intent);

if(currentActivity != null)
currentActivity.finish();
}

在我的 LoginActivity我检查 userId 是否相同,如果是,我尝试通过 onActivityResult 调用重定向用户像这样:
if (getCallingActivity() != null && userId.equals(previouslyLoggedUserId)) 
setResult(RESULT_OK);
else
ApplicationController.startHomeActivity(this);

但这不起作用,因为我设置了标志 FLAG_ACTIVITY_NEW_TASK符合我的 Intent 。如文档中所述:

This flag can not be used when the caller is requesting a result from the activity being launched.



据我了解, Activity只能从 Activity 接收结果从任务。但我需要设置此标志,否则用户将能够返回 Activity stack按后退按钮。

他们是否有任何解决方法来结合 清算 为了避免用户在再次登录之前返回 Activity 和 重定向 我想介绍的行为?

欢迎任何想法,谢谢。

最佳答案

使用 resultreceiver 可能适用于您的设计

关于android - onActivityResult 和 FLAG_ACTIVITY_NEW_TASK : workaround?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51158375/

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