国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag

這篇具有很好參考價(jià)值的文章主要介紹了Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

最近在做一個(gè)人臉識(shí)別相關(guān)的項(xiàng)目,調(diào)用context.startActivity(intent)方法,報(bào)錯(cuò)如下:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?


分析:Activity繼承自Context,查看Context.startActivity(Intent, Bundle),下圖是該方法注釋的一部分:

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag,Android,React-native,android,android studio,ide

說(shuō)明:

如果這個(gè)方法被一個(gè)不是Activity的Context調(diào)用,那么這個(gè)Intent必須包括Intent.FLAG_ACTIVITY_NEW_TASK這個(gè)flag,如果是被Activity的Context調(diào)用,則不需要。

這是因?yàn)?,如果不是被一個(gè)已存在的Activity啟動(dòng),就沒(méi)有已存在的棧去替換新的Activity,所以需要讓它在自身的棧中。所以需要這個(gè)Intent設(shè)置啟動(dòng)參數(shù)Intent.FLAG_ACTIVITY_NEW_TASK這個(gè)flag,讓新Activity在它自身的棧中。

由于我是在React-native當(dāng)中通過(guò)自定義模塊,讓react-native調(diào)用android原生接口(Android native和React-native相互調(diào)用和傳參_曬干的老咸魚(yú)的博客-CSDN博客),該自定義的module初始化如下:

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag,Android,React-native,android,android studio,ide

?定義Context的時(shí)候使用

private ReactApplicationContext mContext;

在使用的時(shí)候,先判斷ReactApplicationContext有沒(méi)有currentActivity,如果有,就拿到Activity對(duì)象,然后通過(guò)該對(duì)象來(lái)啟動(dòng)新的Activity。

if (mContext.hasCurrentActivity()){
               Activity currentActivity = mContext.getCurrentActivity();
               Log.d(TAG, "currentActivity: " + currentActivity);
               WbCloudFaceVerifySdk.getInstance().startWbFaceVerifySdk(currentActivity, new WbCloudFaceVerifyResultListener() {
                  @Override
                  public void onFinish(WbFaceVerifyResult result) {
                     if (result != null) {
                        if (result.isSuccess()) {
                           Log.d(TAG, "刷臉成功!");
                        } else {
                           Log.d(TAG, "刷臉失??!");
                        }
                     }
                     //刷臉結(jié)束后,及時(shí)釋放資源
                     WbCloudFaceVerifySdk.getInstance().release();
                  }
               });
            }
//            callback.invoke(STATUS_SUCCESS);
         }

這里為什么不在一開(kāi)始初始化的時(shí)候定義mContext為Activity的Context,可以參考如下說(shuō)明(ReactContextBaseJavaModule getCurrentActivity 返回空問(wèn)題_曬干的老咸魚(yú)的博客-CSDN博客)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-617260.html

到了這里,關(guān)于Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • spark報(bào)出An error occurred while calling o209.showString.和GC overhead limit exceeded的解決方法

    spark報(bào)出An error occurred while calling o209.showString.和GC overhead limit exceeded的解決方法

    如下圖的錯(cuò)誤解決方法 出現(xiàn)該錯(cuò)誤的原因是因?yàn)榈幚淼臄?shù)據(jù)量太大,jvm的自動(dòng)回收垃圾機(jī)制不完善導(dǎo)致的,比如我在這里對(duì)2千萬(wàn)的數(shù)據(jù)迭代處理24次,數(shù)據(jù)就報(bào)錯(cuò)了。 解決方法一:可以利用isin函數(shù)代替24次迭代過(guò)程 改為 在這里提一句 這一句的作用是把zt列,值為開(kāi)業(yè)的

    2024年02月08日
    瀏覽(34)
  • 解決An error occurred while calling None.org.apache.spark.api.java.JavaSparkContext. : java.lang.Illeg

    java的JDK版本問(wèn)題,由于mac中同時(shí)存在1.8(JDK1.8就是JDK8)和18的版本,將JDK的環(huán)境變量設(shè)置為1.8,降低版本即可。

    2024年02月15日
    瀏覽(18)
  • 使用require.context實(shí)現(xiàn)優(yōu)雅的預(yù)加載

    在前端開(kāi)發(fā)中,對(duì)頁(yè)面 花里胡哨度[注1] 要求越高的頁(yè)面,用到的圖片、音頻什么的就越多,比如什么結(jié)婚請(qǐng)柬、展會(huì)請(qǐng)柬、發(fā)布會(huì)宣傳頁(yè)、數(shù)據(jù)大屏。雖然現(xiàn)在瀏覽器不允許網(wǎng)頁(yè)在沒(méi)有用戶交互的情況下播放音頻,但是,我們依舊要在頁(yè)面展現(xiàn)的同時(shí),準(zhǔn)備好所有的靜態(tài)資

    2024年02月02日
    瀏覽(19)
  • py4j.protocol.Py4JJavaError: An error occurred while calling o116.saveAsTextFile.:

    Traceback (most recent call last): File \\\"C:UsersPycharmProjectspythonProjectBasic18PySpark12.Test.py\\\", line 47, in module json_rdd.saveAsTextFile(\\\"test\\\") File \\\"C:UsersWorkspacesEnvpythonProjectBasiclibsite-packagespysparkrdd.py\\\", line 2205, in saveAsTextFile keyed._jrdd.map(self.ctx._jvm.BytesToString()).saveAsTextFile(path) File \\\"C:UsersWorks

    2024年02月05日
    瀏覽(17)
  • 新建或刪除名稱空間報(bào)錯(cuò):Error from server (InternalError): Internal error occurred: failed calling webhook

    新建或刪除名稱空間報(bào)錯(cuò):Error from server (InternalError): Internal error occurred: failed calling webhook

    一,詳細(xì)報(bào)錯(cuò)信息 強(qiáng)制刪除某個(gè)名稱空間后,再創(chuàng)建提示報(bào)錯(cuò)如下: ?Error from server (InternalError): Internal error occurred: failed calling webhook \\\"rancher.cattle.io.namespaces.create-non-kubesystem\\\": failed to call webhook: Post \\\"https://rancher-webhook.cattle-system.svc:443/v1/webhook/validation/namespaces?timeout=10s\\\": servic

    2024年02月15日
    瀏覽(18)
  • vue3 + naive ui + Tabs 報(bào)錯(cuò) ‘Slot “default“ invoked outside of the render function‘

    警告的異常信息: 解決方法: 如下給Tabs組件加一個(gè)defaultValue的默認(rèn)值即可 參考:https://github.com/tusen-ai/naive-ui/issues/3134

    2024年01月21日
    瀏覽(24)
  • 解決CitSpace分析新版本web of science文獻(xiàn)報(bào)錯(cuò)“the timing slicing setting is outside the range of your data”

    解決CitSpace分析新版本web of science文獻(xiàn)報(bào)錯(cuò)“the timing slicing setting is outside the range of your data”

    新版web of science于2021年7月7日上線,舊版 Web of Science 將同步運(yùn)行到2021年底?,F(xiàn)在舊版web of science入口早已關(guān)閉,新本web of science的殘產(chǎn)品中也不在提供舊頁(yè)面入口。 近來(lái)在使用web of science文獻(xiàn)制作CiteSpace圖譜時(shí)發(fā)現(xiàn),web of science導(dǎo)出的文獻(xiàn)數(shù)據(jù)在CiteSpace跑的時(shí)候都會(huì)出現(xiàn)“th

    2024年02月02日
    瀏覽(29)
  • Vue中使用require.context自動(dòng)引入組件的方法介紹

    目錄 一、自動(dòng)引入組件 1、語(yǔ)法 2、使用 2.1、在compoents文件下隨便創(chuàng)建index.js文件 2.2、mian.js引入該js 二、自動(dòng)生成路由 1、示例: 2、使用 2.1、在router文件下隨便創(chuàng)建autoRouter.js文件 2.2、在router文件下index.js文件中引入autoRouter.js文件 三、總結(jié) 一、自動(dòng)引入組件 我們項(xiàng)目開(kāi)發(fā)

    2024年02月03日
    瀏覽(18)
  • Vue 項(xiàng)目路由、自定義指令、api方法自動(dòng)引入資源(require.context使用)

    Vue 項(xiàng)目路由、自定義指令、api方法自動(dòng)引入資源(require.context使用)

    require.context(directory,useSubdirectories,regExp) 1:directory:哪個(gè)文件夾 2:useSubdirectories:是否需要找到子文件夾 3: regExp:正則表達(dá)式(一般指文件的后綴) 以下是單個(gè)js文件 接口的命名不能重復(fù)。 如果項(xiàng)目較大,建議接口命名需要有一個(gè)統(tǒng)一的規(guī)范來(lái)避免出現(xiàn)命名重復(fù)的問(wèn)題

    2024年02月16日
    瀏覽(51)
  • Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0

    Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0

    項(xiàng)目: taro3+vue3 描述:運(yùn)行時(shí)警告 Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0. 原因:sass版本的問(wèn)題, 換成calc 方法一:sass-migrator 全局安裝 sass-migrator, 在node_modules/.bin中運(yùn)行 sass-migrator division ./node_modules/taro-ui-vue3/dist/style/components/*.

    2024年02月11日
    瀏覽(21)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包