android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context...
参考博客: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...相关推荐
- Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity
Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity ...
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK fla
/*在一个Activity中写了如下代码*/ mContext=getApplicationContext(); mContext.startActivity(intent); 报错 W/System ...
- startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIV
Android 高手核心知识点笔记(不断更新中
- 异常处理方式 Calling startActivity() from outside of an Activity
Calling startActivity() from outside of an Activity 在Activity中使用startActivity()很简单,但是如果是在其他地方(如Widge ...
- startActivity在Activity和Service中的不同实现,以及“Calling startActivity() from outside of an Activity”错误解决
startActivity简介: 在Android应用开发过程中,通过调用startActivity可以启动另外一个Activity,参数必须包含Intent.例如, Intent intent = ...
- android.util.AndroidRuntimeException: requestFeature() must be called before adding content
问题 Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding co ...
- android错误-android.util.AndroidRuntimeException:You cannot combine custom titles with other title
报如下错误:android.util.AndroidRuntimeException: You cannot combinecustom titles with other title feature ...
- E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher android.util.AndroidRuntimeException: Animators
错误 运行android项目 控制台报错 android.util.AndroidRuntimeException: Animators may only be run on Looper threa ...
- 报如下错误:android.util.AndroidRuntimeException: You cannot combine custom titles with other title featur
解决方法: 后来,我直接在 AndroidManifest.xml 中,将android:theme="@style/AppTheme" 直接改成android:theme=&qu ...
- 错误:android.util.SuperNotCalledException
android.util.SuperNotCalledException: Activity {--.YouTubePlayActivity} did not call through to supe ...
最新文章
- 拿haojava官方过程
- 连续低频脑电图解码手臂运动,实现机械手臂的闭环自然控制
- libevent在windows下使用步骤详解
- 在SQL Server 20005中修改存储过程
- 3ds Max制作客厅场景实例教程
- JVM工作原理和特点
- 学习使用bilstm_crf_model出现的bug
- windows驱动开发详解学习笔记
- java indexof方法_【3-14】Java中集合类list的增删改查
- VS Code 中的文件添加图标的插件vscode-icons
- 10个学习Android开发的网站推荐
- 14-mysql-分页查询
- 【Redis】Redis Bitmaps
- Asp.net主题(theme)和皮肤(skin)的使用
- Redis实战篇(视频学习来自黑马程序员)
- 富勒wms系统里的定时器id_为什么物流行业非常推崇仓库管理系统?
- 基于MFC的OpenDDS发布订阅例子(idl)
- 移动端UML图应用之UML图简述
- python和html和css什么关系什么区_Python 【第七章】:Html 和 CSS
- 免费下载 [discuz!插件] 404页死链优化SEO V2.6