我正在尝试从嵌套回收器视图中打开自定义 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
这是我用来打开自定义 chrome 选项卡的代码
val builder = CustomTabsIntent.Builder()
val customTabsIntent = builder.build()
customTabsIntent.launchUrl(context.applicationContext, Uri.parse("https://www.codingkaro.in"))
这是在嵌套回收器视图内的按钮点击侦听器上设置的。我已将 MainActivity 中的 context
作为 this@MainActivity
传递
这是我遇到的错误
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?
之前我不知道如何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"))
一切正常。
我刚刚添加
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
这是我用来打开自定义 chrome 选项卡的代码
val builder = CustomTabsIntent.Builder()
val customTabsIntent = builder.build()
customTabsIntent.launchUrl(context.applicationContext, Uri.parse("https://www.codingkaro.in"))
这是在嵌套回收器视图内的按钮点击侦听器上设置的。我已将 MainActivity 中的 context
作为 this@MainActivity
这是我遇到的错误
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?
之前我不知道如何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"))
一切正常。
我刚刚添加
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)