[英]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.