简体   繁体   English

我正在尝试从嵌套回收器视图中打开自定义 chrome 选项卡,但无法从 Activity 外部调用 startActivity() 时出错

[英]I am trying to open custom chrome tab from nested recycler view but couldn't having error Calling startActivity() from outside of an Activity

Here is the code I am using to open the custom chrome tab这是我用来打开自定义 chrome 选项卡的代码

val builder = CustomTabsIntent.Builder()
                val customTabsIntent = builder.build()
                customTabsIntent.launchUrl(context.applicationContext, Uri.parse("https://www.codingkaro.in"))

This is set on a button click listener inside nested recycler view.这是在嵌套回收器视图内的按钮单击侦听器上设置的。 I have passed the context from the MainActivity as this@MainActivity我已经将 MainActivity 的context传递为this@MainActivity

This is the error I am getting这是我得到的错误

Process: com.shyptsolution.classproject, PID: 31505
    android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

Earlier I didn't know how to addFlags() to this but now the code looks like this早些时候我不知道如何将addFlags()添加到此,但现在代码看起来像这样

val builder = CustomTabsIntent.Builder()
                val customTabsIntent = builder.build()
                customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                customTabsIntent.launchUrl(holder.download.rootView.context, Uri.parse("https://www.codingkaro.in"))

and everything works fine.一切正常。 I just added customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)我刚刚添加了customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

暂无
暂无

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

相关问题 从Activity外部调用startActivity() - Calling startActivity() from outside of an Activity 从漫画适配器中的 Activity 外部调用 startActivity() 如何解决这个问题 - Calling startActivity() from outside of an Activity in comic adapter how to solved this one android.util.AndroidRuntimeException:从Activity外部调用startActivity() - android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity 如何修复 java 中的“从 Activity 上下文外部调用 startActivity() 需要...”错误 - How to fix 'Calling startActivity() from outside of an Activity context requires ...' error in java 使用 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 如何从主要活动之外运行startActivity - How to run startActivity from outside of the main activity 如果我未从其他路径打开活动,则startActivity崩溃 - startActivity crashes if I do not open the activity from another path 我正在尝试使用回收站视图从 Firebase 数据库中检索数据,但出现错误 - i am trying to retrieve the data from fire base database using recycler view but i am getting errors in it 虽然已经设置了标志 - 从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 从 Activity 上下文外部调用 startActivity() 需要 FLAG_ACTIVITY_NEW_TASK 标志。 这真的是你想要的吗? - Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM