如何从其他活动转到已经存在的活动 [英] How to go to an already existing activity from a different one

查看:75
本文介绍了如何从其他活动转到已经存在的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是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个分别称为ABActivity,并且都开始使用,如何在不声明Activity的新实例且不点击后退按钮的情况下切换Activity .在两个Activity中,我对另一个都有全局引用.如何使用setVisible()方法?文档似乎并没有使我明白这一点.

Say I have 2 Activitys called A and B and both getting started, how do i switch the Activitys without declaring a new instance of the Activitys and without hitting the back button. in both Activitys 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屋!

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