如何从其他活动转到已经存在的活动 [英] How to go to an already existing activity from a different one
问题描述
首先,我是Android编程的新手.我有一个很简单的问题,在任何地方都找不到答案.
To start off I am new to Android programming. I have a pretty straight forward question and I couldn't find an answer anywhere.
说我有2个分别称为A
和B
的Activity
,并且都开始使用,如何在不声明Activity
的新实例且不点击后退按钮的情况下切换Activity
.在两个Activity
中,我对另一个都有全局引用.如何使用setVisible()
方法?文档似乎并没有使我明白这一点.
Say I have 2 Activity
s called A
and B
and both getting started, how do i switch the Activity
s without declaring a new instance of the Activity
s and without hitting the back button. in both Activity
s I have a global reference to the other one. do I use the setVisible()
method? the documentations didn't seem to clear me up about this.
谢谢.
推荐答案
我使用setVisible方法吗?
do i use the setVisible method?
不.那只会在膨胀的Views/layouts
上起作用.在正常情况下,调用layout
不在堆栈顶部的任何layout
都不可见.
No. That will only work on inflated Views/layouts
. The layout
that is in whichever Activity
is not on the top of the stack will not be visible to call this method on, under normal circumstances.
在您的onClick()
Intent i = new Intent(CurrentActivityName.this, NextActivityName.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
来自文档
如果在传递给Context.startActivity()的Intent中进行设置,则此标志将使已启动的活动(如果已在运行中)置于其任务的历史记录堆栈的最前面.
If set in an Intent passed to Context.startActivity(), this flag will cause the launched activity to be brought to the front of its task's history stack if it is already running.
这篇关于如何从其他活动转到已经存在的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!