我有活动的导航问题,返回堆叠,我希望你能清除它为我说话。
问题
根系活力>>> SecondActivity >>为homeButton
这就需要我的主页,并从那里我选择...
Gmail的>>留言>>在我的应用程序中打开附件>> ImportActivity >> RootActivity
结果是正在启动一项新的任务和所用我的应用程序的另一个实例。 这是不可接受的,因为我不希望两个独立的任务运行的我只想要一个做。
期望的结果
我希望发生的是,当用户打开附件和ImportActivity完成什么它做什么(它android:noHistory
设置为true),并调用startActivity(intent)
, RootActivity
启动,但只保留一个实例和活动的其余部分在原有任务(在这种情况下,它的上面SecondActivity
)将被删除。
我想这样做的原因是,如果用户在导入文件后,导航了我的申请后,再触摸它加载的第一个任务,其背部栈的应用图标,然后我在运行中,用户可以在两个不同地方的两个任务我的应用程序一次。
我曾尝试
我已经打得四处发射模式,但没有人真的给我我需要的功能。
启动模式我都试过..
机器人:launchMode =“singleTask” -这只是每次推出时再次启动根系活力。 即使用户按下home键我的应用程序中,碰到的应用图标后面堆被破坏。
机器人:launchMode =“singleInstance =不允许任何其他activites在任务中运行。
还要求意向启动的时候RootActivity
我用下面无济于事。
Intent i = new Intent(ImportActivity.this,TrackingActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
是否有可能做我想做什么?
提前致谢
You say
Gmail >> Message >> Open attachment in my application >> ImportActivity >> RootActivity
but that may not be right. In this circumstance, gmail will issue an Intent
targeted at the ImportActivity
in your app. ImportActivity
will execute. However, my reading of https://developer.android.com/guide/components/tasks-and-back-stack.html suggests that ImportActivity
will execute as part of the same task as gmail and will be put on top of the back stack for the gmail task, unless you take special steps in the manifest to prevent that or gmail specifically invokes it as a separate task. When ImportActivity
finishes, it shouldn't call startActivity(intentForRootActivity)
but should just call finish()
so that it will be destroyed and the activity from gmail which lies underneath it in the back stack will appear.
If ImportActivity
did call startActivity(intentForRootActivity)
then RootActivity
would just go onto the top of the gmail task and appear on the gmail back stack. Touching home
and then the launcher icon for gmail would see RootActivity
reappear, hiding gmail underneath.
I think you need android:launchMode="standard"
in the manifest declaration of ImportActivity
.
The task which represents the older, stand-alone instance of your app will not be modified. If someone touches the launcher icon for your app, the old state of your app will be restored, unaffected by whatever happened in the gmail task.
The document http://developer.android.com/guide/components/processes-and-threads.html is rather vague about how Activities map onto processes here (causing David Wasser to comment on my earlier version of this answer) but it seems that the Activities of gmail will execute in one linux process with one linux user id and the ImportActivity
will execute in another linux process with another user id. However, they can all form part of one task with one back stack.
ImportActivity
will execute, as part of the gmail task, with the same effective Linux User ID as it would had it executed as part of your standalone app - and different from the Linux user ID that gmail executes with. This sounds unlikely and complicated but seems to be implied by https://developer.android.com/guide/components/fundamentals.html. That makes sense; if ImportActivity
needs to get at, say, the user preferences stored for your app, it needs to read the preference file as if it were the user defined for your app, not the user defined for gmail.
I haven't tried executing any of this. If I have hold of entirely the wrong end of the stick, I'm sure someone will soon tell us!
你不应该需要任何特殊的launchMode
做到这一点。 如果您的进口活动启动根系活力与Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
这应该做你想做的。 我猜你有一个问题taskAffinity
。 试试这个:
在您的清单,在声明中importActivity补充一点:
android:taskAffinity=""
如果这不起作用,请发表您的清单,所以我们可以看看它。
我真的不知道,如果我得到它,但如果你想要去你的“根”活动与出松动额外应用程序堆栈,这将是Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
上的标志指示你的intent
,并与没有额外CONFIGS Manifest
......如果你需要单独的任务来创建一个新的完整的新的堆栈比你可以使用Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
像你描述。