android - 返回上一屏幕而不创建新实例

标签 android

enter image description here

如图所示,流程是这样的。因此,每当用户单击 Logo 按钮时,都应调用 Activity A。作为简单的解决方案,我们可以使用这种方法...

Intent intent = new Intent(activity, activityToStart);
startActivity(intent);

但是此 Activity 将为我的应用创建一个新 Activity 。但是我需要调用相同的 Activity 实例,因为我们在流程图中前进。通过调用 finish() 可以很容易地调用从 Activity A 到 B,然后再次在 B 上调用,但是从 Activity C 或 D,如何返回到 A。

我的想法已经用完了,但没有得到任何富有成果的结果。如果您有任何建议或在我出错的任何地方,请帮助我。提前致谢。

最佳答案

要从 D 返回到 A,请使用 Intent Flags。

Intent intent = new Intent(activity, activityToStart);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent);

FLAG_ACTIVITY_CLEAR_TOP,将不会创建新 Activity ,而是调用堆栈上的 Activity ,并将所有 Activity 弹出到被调用的 Activity 上。

关于android - 返回上一屏幕而不创建新实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11715848/

相关文章:

Android ndk-build错误make.exe : *** create_child_process: DuplicateHandle(In) failed (e=6)

android - 水平对齐 ImageView 和 EditText

javascript - 如何在 React Native 中将选择器数据传递到 API

android - RecyclerView 消失的图片

android - COCOS-2d-x : Idea to implement Level progress in games

Android LayoutInflater 内存不足

android - 通过 MainActivity 添加 webview

android - 具有两种功能的动态按钮 ANDROID

android - 在android中通过语音匹配访问

android - 应用程序被销毁后立即发出通知