参考博客:https://blog.csdn.net/u010665691/article/details/43372517

问题描述:

通过外部Activity的上下文调用startActivity(),需要添加FLAG_ACTIVITY_NEW_TASK标志。

  因为 Activity 与 Context 中都有一个 startActivity() 的方法,而 Activity 是 Context 的子类,在 Activity 中会重载 startActivity() 方法,所以两个方法存在区别。使用 Activity 中的方法没有任何的限制,但是如果使用的是 Context 中的方法,则需要添加一个标志 FLAG_ACTIVITY_NEW_TASK 来开启一个新的任务,否则就会遇到上述的问题。

引入位置:

mContext.startActivity(new Intent(MainActivity.this, OtherActivity.class));

解决方法:

1、方法一:添加 FLAG_ACTIVITY_NEW_TASK

Intent intent = new Intent(MainActivity.this, RcActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);

2、方法二、在Activity中直接使用startActivity()方法

Intent intent = new Intent(MainActivity.this, RcActivity.class);
startActivity(intent);

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context...相关推荐

  1. Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity

    Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity ...

  2. Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK fla

    /*在一个Activity中写了如下代码*/ mContext=getApplicationContext(); mContext.startActivity(intent); 报错 W/System ...

  3. startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIV

    Android 高手核心知识点笔记(不断更新中

  4. 异常处理方式 Calling startActivity() from outside of an Activity

    Calling startActivity() from outside of an Activity 在Activity中使用startActivity()很简单,但是如果是在其他地方(如Widge ...

  5. startActivity在Activity和Service中的不同实现,以及“Calling startActivity() from outside of an Activity”错误解决

    startActivity简介: 在Android应用开发过程中,通过调用startActivity可以启动另外一个Activity,参数必须包含Intent.例如, Intent intent = ...

  6. android.util.AndroidRuntimeException: requestFeature() must be called before adding content

    问题 Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding co ...

  7. android错误-android.util.AndroidRuntimeException:You cannot combine custom titles with other title

    报如下错误:android.util.AndroidRuntimeException: You cannot combinecustom titles with other title feature ...

  8. E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher android.util.AndroidRuntimeException: Animators

    错误 运行android项目 控制台报错 android.util.AndroidRuntimeException: Animators may only be run on Looper threa ...

  9. 报如下错误:android.util.AndroidRuntimeException: You cannot combine custom titles with other title featur

    解决方法: 后来,我直接在 AndroidManifest.xml 中,将android:theme="@style/AppTheme" 直接改成android:theme=&qu ...

  10. 错误:android.util.SuperNotCalledException

    android.util.SuperNotCalledException: Activity {--.YouTubePlayActivity} did not call through to supe ...

最新文章

  1. 拿haojava官方过程
  2. 连续低频脑电图解码手臂运动,实现机械手臂的闭环自然控制
  3. libevent在windows下使用步骤详解
  4. 在SQL Server 20005中修改存储过程
  5. 3ds Max制作客厅场景实例教程
  6. JVM工作原理和特点
  7. 学习使用bilstm_crf_model出现的bug
  8. windows驱动开发详解学习笔记
  9. java indexof方法_【3-14】Java中集合类list的增删改查
  10. VS Code 中的文件添加图标的插件vscode-icons
  11. 10个学习Android开发的网站推荐
  12. 14-mysql-分页查询
  13. 【Redis】Redis Bitmaps
  14. Asp.net主题(theme)和皮肤(skin)的使用
  15. Redis实战篇(视频学习来自黑马程序员)
  16. 富勒wms系统里的定时器id_为什么物流行业非常推崇仓库管理系统?
  17. 基于MFC的OpenDDS发布订阅例子(idl)
  18. 移动端UML图应用之UML图简述
  19. python和html和css什么关系什么区_Python 【第七章】:Html 和 CSS
  20. 免费下载 [discuz!插件] 404页死链优化SEO V2.6

热门文章

  1. Priest John's Busiest Day (2-sat)
  2. bagku秋名山老司机
  3. STM32物联网套件基础版03-控制继电器
  4. 毕业生的商业软件开发之路 --- 现代商业软件开发概况
  5. 微信企业号开发-如何建立连接
  6. 屏幕保护程序Aerial Mac
  7. 怎样以两种方式从Mac计算机上的启动板菜单中删除应用程序?
  8. 图像的指纹——从自然图片到GAN
  9. Python函数嵌套/递归(七)-----详细
  10. 头同尾合十的算法_尾同头合十或头同尾合十等的速算方法word精品