独立于其他活动运行 Android 应用程序特定活动 [英] Running android apps particular activity independently than rest of activities

查看:40
本文介绍了独立于其他活动运行 Android 应用程序特定活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题已解决,为未来的访客提供答案

THIS QUESTION IS SOLVED, PROVIDING ANSWER FOR FUTURE SO VISITORS BELOW

上下文:

我正在开发一个默认的手机应用.它处理来自我的应用程序的 action.DIALaction.CALL 以及它也处理来自其他应用程序的这两个意图.

I am developing a default phone app. Which handles action.DIAL and action.CALL from My application as well as it handles these both intents from other apps too.

什么问题:

如果我的 CallActivity 正在运行(如果有任何呼叫正在进行)那么 -

If my CallActivity is running ( if any call is ongoing ) then -

  1. 当我再次尝试打开我的应用时,它只向我显示 CallActivity.
  2. 因此,我无法通过打开应用程序再次拨打电话.

ma​​nifest.xml 的样子:

<application
    android:allowBackup="true"
    android:directBootAware="true"
    android:fullBackupContent="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.CALL_BUTTON" />

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

    <activity
        android:name=".CallActivity"
        android:label="@string/title_activity_call"
        android:process=":CallManager"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter android:priority="800">
            <action android:name="android.intent.action.ACTION_CALL" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>
</application> 

我在搜索上述问题时发现了什么:

https://stackoverflow.com/questions/9458300/how-to-create-an-android-activity-and-service-that-use-separate-processes

我做了哪些努力:

您可以注意到我在 manifest 中为我的 CallActivity

You can note i tried android:process=":CallManager" attribute in manifest for my CallActivity

是否解决了问题:

没有.每当 CallActivity 运行时,我仍然无法打开我的 MainActivity.但是导致的问题是,现在我的通话没有结束,因为这完全是另一个进程,它无法引用旧进程中保留的其他调用.

Nope. I am still unable to open my MainActivity, whenever CallActivity is running. But is caused the problem that now my call is not getting ended as this is completely another process it is unable to reference other calls which remain there in older process.

答案

android:process 是否正确:

在这种情况下完全没有,因为当我们的应用程序内存使用量增加超过特定限制时使用它 android 开始缓存其服务和资源以避免它开发人员通常使用 android:process允许他们使用相同堆大小的另一个堆内存.

No not at all in this case, as it is used when our app memory usage increases over particular limit android starts caching its services and resources in order to avoid it developers generally use android:process which allows them another heap memory available with same heap size.

** 什么问题:**

它与任务及其亲和力有关两个活动都需要为任务和它们的关联性分开

It was related to task and its affinities Both activities needed to be separated for tasks and their affinities

喜欢:

<activity
android:name="com.example.ActivityA"
android:label="Activity A"
android:launchMode="singleInstance"
android:taskAffinity="com.example.AffinityA" >
</activity>
<activity
android:name="com.example.ActivityB"
android:label="Activity B"
android:launchMode="singleInstance"
android:taskAffinity="com.example.AffinityB" >
</activity>

我必须感谢 @JayWozz 对 SO https://stackoverflow.com/a/45488126/9810130 并且必须欣赏 @感谢 gabe-sechan,感谢他真诚的帮助和努力,并为此线程付出了宝贵的时间.

I must thanks @JayWozz for his answer over SO https://stackoverflow.com/a/45488126/9810130 and must appreciate @gabe-sechan for his sincere help and efforts and for giving his value-able time for this thread.

推荐答案

我认为您基本上是在要求一系列新的活动.尝试使用 FLAG_ACTIVITY_NEW_DOCUMENT| 启动意图FLAG_ACTIVITY_MULTIPLE_TASKS 这将启动 Activity,就好像它是一组新的 Activity,在最近的应用程序列表中有它自己的单独列表.在 https://developer.android.com/reference/android 上查看这些标志的定义/内容/意图

I think you're basically asking for a new stack of activities. Try launching the intent with FLAG_ACTIVITY_NEW_DOCUMENT| FLAG_ACTIVITY_MULTIPLE_TASKS That will launch the activity as if its a new set of activities, with its own separate listing in the recent apps list. See the definiton of these flags at https://developer.android.com/reference/android/content/Intent

这篇关于独立于其他活动运行 Android 应用程序特定活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆