对话活动也继续在后台等活动后台、继续

2023-09-12 05:13:49 作者:何日不离伤

这是该方案。我有2个活动,我的应用程序,并且在开始时,我点击我的应用程序创建的通知的对话活动。 问题是,当我点击该通知,只有对话框应该显示,而不是我的应用程序的其他活动,如果它被停止了pressing home键。

This is the scenario. I have 2 activities in my application and a Dialog activity that is started when I click on the notification created by my application. The problem is that when I click on the notification, only the Dialog should show, not the other activity of my app, if it was stopped on pressing the home button.

在我附近pressing后退按钮我的应用程序,对话活动显示的对话框,但是当应用程序在后台运行时,此活动还创造了对话活动打开了。

When I close my application by pressing the back button, the dialog activity shows the dialog, but when the application is running in the background, that activity also opens up on creating the dialog activity.

我用 @android:款式/ Theme.Dialog 我的对话活动。

如何只显示对话框的活动,而不是其他活动的研究背景?

How to only show the Dialog activity, not other activities in the backgroud?

推荐答案

该解决方案的任择议定书问题设置不同的任务亲和力清单中的活动。

The solution to the OP issue is setting a different Task affinity for that activity in the Manifest.

<activity android:name="MyIndependentActivity"
android:theme="@android:style/Theme.Dialog" 
android:taskAffinity="a_unique_id">

在taskAffinity字符串必须是从包名称不同(com.whatever.myapp)

The taskAffinity string must be different from the package name (com.whatever.myapp)

我还使用机器人:excludeFromRecents =真,隐藏从最近的应用程序列表的对话框,因为它通常是没有意义返回到对话框

I also use android:excludeFromRecents="true", to hide the dialog from the recent apps list, as it usually makes no sense returning to a dialog.

更多信息:的http://developer.android.com/guide/components/tasks-and-back-stack.html#Affinities