简体   繁体   English

错误FLAG_ACTIVITY_NEW_TASK标志

[英]error FLAG_ACTIVITY_NEW_TASK flag

Hi I try to build an app, but I have the next error when I logout app, my app use login users, but when press logout show me this: 嗨,我尝试构建一个应用程序,但是注销应用程序时出现下一个错误,我的应用程序使用登录用户,但是按注销时,向我显示以下内容:

error 错误

android.util.AndroidRuntimeException: Calling startActivity() from 
outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK
flag. Is this really what you want?

logout code 注销代码

public void logout() {
   SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
   SharedPreferences.Editor editor = sharedPreferences.edit();
   editor.clear();
   editor.apply();
   mCtx.startActivity(new Intent(mCtx, LoginActivity.class));
}

This is because you're trying to start the activity using mCtx which is a non-activity context. 这是因为您正在尝试使用mCtx (一个非活动上下文)来启动活动。 You need to use the Activity where logout method reside, something like this: 您需要使用logout方法所在的Activity,如下所示:

public void logout() {
  ...
  startActivity(new Intent(this, LoginActivity.class));
  // or use YourActivity.this instead of this
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 关于上下文FLAG_ACTIVITY_NEW_TASK的错误 - error about context FLAG_ACTIVITY_NEW_TASK 处理FLAG_ACTIVITY_NEW_TASK的NewIntent - Handling onNewIntent for FLAG_ACTIVITY_NEW_TASK Android FLAG_ACTIVITY_NEW_TASK无效 - Android FLAG_ACTIVITY_NEW_TASK not working 使用 Intent.createChooser 并出现错误:从 Activity 上下文外部调用 startActivity() 需要 FLAG_ACTIVITY_NEW_TASK 标志 - Using Intent.createChooser and getting error: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag 使用FLAG_ACTIVITY_NEW_TASK恢复播放后停止音乐 - Stop music after resume using FLAG_ACTIVITY_NEW_TASK FLAG_ACTIVITY_NEW_TASK 在 react native 中集成 android native 库时出错 - FLAG_ACTIVITY_NEW_TASK error integrating android native library in react native 解析活动上下文需要FLAG_ACTIVITY_NEW_TASK标志。 这真的是您想要的吗? - Resolve Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? 上下文需要 FLAG_ACTIVITY_NEW_TASK 但我已经设置了那个标志 - Context wants FLAG_ACTIVITY_NEW_TASK but I've already set that flag 虽然已经设置了标志 - 从Activity上下文外部调用startActivity()需要FLAG_ACTIVITY_NEW_TASK标志 - Although flag is already set - Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag Android Studio - 如何修复使用 flag_activity_clear_task 后后退按钮仍然有效 | flag_activity_new_task? - Android Studio - How to fix back button still working after using flag_activity_clear_task | flag_activity_new_task?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM