检测活动是否从片段运行

发布于 2025-02-01 13:15:44 字数 1885 浏览 2 评论 0原文

因此,我正在构建一个在单个活动和多个片段上运行的应用程序。

功能之一是使用第三方应用程序,在该应用程序中,我将使用其SDK向其服务器发送事件,并且为了响应,我应该获得触发动画的意图。如果未触发第三方活动,第三方不会产生问题。

就我而言,我的意图过滤器如下:

   <activity
            android:name="sdk.abc.io.activities.GateActivity"
            android:exported="true"
            android:launchMode="singleInstance">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="abc-keyxxx" />
            </intent-filter>
     

因此,当加载片段A时,它使用SDK向ABC服务器提交事件。 ABC服务器应该发回意图并启动gateactitivity

在某些情况下,未收到意图,我会陷入片段A。

我的片段正在运行以下代码:

   override fun onResume() {
        super.onResume()
        if(viewModel.isAbcHasBeenStarted()) {
            mainViewModel.hideProgress()
            goToNextPage()
        } else {
            mainViewModel.showProgress
            viewModel.startAbcFlow()
        }
    }

如果触发ABC活动,则该效果正常,因为当我离开活动ABC时,生命周期时,生命周期,让我按照我的计划。如果ABC活动未启动(没有收到意图),那么我一直在片段A中

留下在请求之后,我们正在运行2秒,如果没有,我只是将导航从片段A触发到我需要的任何视图。

override fun onResume() {
        super.onResume()
        if(viewModel.isAbcHasBeenStarted()) {
            mainViewModel.hideProgress()
            goToNextPage()
        } else {
            mainViewModel.showProgress
            viewModel.startAbcFlow()
            Handler().postDelayed({
                isActivityStarted()
            }, 3000)
        }
    }

   fun isActivityStarted() {
      //check if sdk.abc.io.activities.GateActivity is started
}

我不知道如何正确检查sdk.abc.io.activities.gateactivition是否正在运行或开始运行或启动以免被我的片段粘在我的片段中

So I am building an app which is running on a single activity and multiple fragments.

One of the feature is using a 3rd party application where I am sending an event to their servers using their SDK and in response I am supposed to get an intent which trigger an animation. The 3rd parties doesn't generate issue if the 3rd parties activities is not triggered.

In my case, I have the intent-filter as below:

   <activity
            android:name="sdk.abc.io.activities.GateActivity"
            android:exported="true"
            android:launchMode="singleInstance">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="abc-keyxxx" />
            </intent-filter>
     

So, when my fragment A is loaded, it submit an event to the abc server using the sdk. The ABC server is supposed to send back an intent and launch the GateActivity.

In some cases, the intent is not received and I get stuck in my Fragment A.

My fragment is running a code as below:

   override fun onResume() {
        super.onResume()
        if(viewModel.isAbcHasBeenStarted()) {
            mainViewModel.hideProgress()
            goToNextPage()
        } else {
            mainViewModel.showProgress
            viewModel.startAbcFlow()
        }
    }

This working fine in case the Abc activity is triggered because when I am leaving the activity Abc, the lifecycle let me act as I was planning. If the Abc activity doesn't start (no intent received), I stay for ever in the Fragment A.

I was hoping to find a way to check in the onResume of my Fragment A if the Abc activity is running let's say 2sec after the request and if not, I am just triggering the navigation from the Fragment A to any view I need.

override fun onResume() {
        super.onResume()
        if(viewModel.isAbcHasBeenStarted()) {
            mainViewModel.hideProgress()
            goToNextPage()
        } else {
            mainViewModel.showProgress
            viewModel.startAbcFlow()
            Handler().postDelayed({
                isActivityStarted()
            }, 3000)
        }
    }

   fun isActivityStarted() {
      //check if sdk.abc.io.activities.GateActivity is started
}

I have no clue how to properly check in the sdk.abc.io.activities.GateActivity is running or started in order to not get stuck in my Fragment

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文