简历,而不是启动活动,如果已经存在于回栈 [英] Resume the Activity instead of Starting if already exists in back stack

查看:170
本文介绍了简历,而不是启动活动,如果已经存在于回栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Activity_1 经过很多步骤,比如

I have an Activity_1 after a lot of steps, say

Activity_2 > Activity_3 ....在某些 Activity_n 更改相关的 Activity_1 ,并调用它使用

Activity_2 > Activity_3 .... in some Activity_n I change some data related to Activity_1 and call it using

Intent intent = new Intent(Activity_n.this, Activity_1.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

要刷新内容。但后来我可以去所有的方式回到 Activity_1 在那里我开始有旧数据。

To refresh the content. But later I can go all the way back to Activity_1 where I started, which has old data.

相反,我想最初的 Activity_1 onResume()被调用,使用上述code。或适当的标志

Instead I want the initial Activity_1' s onResume() to be called, using the above code. Or appropriate Flag

FLAG_ACTIVITY_CLEAR_TOP

考虑由活动的任务:A,B,C,D。若D电话   startActivity()与解析的组件的意图   活动B,然后是C和D将完成和B接收定   意图,导致堆栈现在是:A,B

consider a task consisting of the activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then C and D will be finished and B receive the given Intent, resulting in the stack now being: A, B.

这是什么文档说,但是不知道我得到。

That' what the docs say, but not what I am getting.

推荐答案

您可以添加此两条线,并尝试

You can add this two lines and try

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

在你里面的活动清单文件

写这个

Write this in your manifest file inside Activity

   <activity
        android:name=".SettingsActivity"
        android:launchMode="singleInstance"
        android:screenOrientation="portrait" >
    </activity>

singleTask和singleInstance活动只能开始的任务。它们总是在活动堆的根。此外,该设备可以容纳的活性只有一个实例在一个时间 - 。仅一个这样的任务

"singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task.

您可以使用SingleTask或SingleInstance

You can use SingleTask or SingleInstance

singleTask - 系统将创建在一个新的任务和路线的意图,它的根活动。但是,如果已经存在该活动的一个实​​例,该系统的路线,通过调用其onNewIntent()方法,而不是创建一个新的。

"singleTask" - The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.

singleInstance - 同singleTask,所不同的是,系统不启动任何其他活动到任务保持该实例。该活动是永远的任务单,唯一成员。

"singleInstance" - Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task.

请参考以下链接<一个href="http://developer.android.com/guide/topics/manifest/activity-element.html">http://developer.android.com/guide/topics/manifest/activity-element.html

这篇关于简历,而不是启动活动,如果已经存在于回栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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