如何在没有调用 onCreate() 的情况下返回第一个活动 [英] How to come back to First activity without its onCreate() called

查看:17
本文介绍了如何在没有调用 onCreate() 的情况下返回第一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3 个活动.活动 A、活动 B、活动 C.这是流程 A->B->C.现在我想从 C 进入活动 A.(即 C->A)而不需要调用活动 A 的 onCreate().

I have 3 activity . Activity A ,Activity B, Activity C. This is the flow A->B->C. Now i want to come to activity A from C .(i.e C->A) without getting its onCreate() called of Activity A.

到目前为止,我的代码是:但它会调用 ActivityA 的 onCreate().我想调用 Restart().

so far my code is:But it will call onCreate() of ActivityA. I want to call Restart().

Intent intent=new Intent(ActivityC.this,ActivityA.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                finish(); 

推荐答案

两种情况:

  1. 如果您想让其他活动保持活动状态并且只想将 A 放在前面,只需使用意图标志 FLAG_ACTIVITY_REORDER_TO_FRONT.

  1. If you want to keep other activities live and just want to bring A to front, just use intent flag FLAG_ACTIVITY_REORDER_TO_FRONT.

如果您不想清除所有活动并希望现有的 A 实例位于顶部,请使用意图标志 FLAG_ACTIVITY_CLEAR_TOP 和 FLAG_ACTIVITY_SINGLE_TOP.

If you don't want to clear all activities and want existing instance of A at top, then use intent flags FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP.

注意:如果您只使用 FLAG_ACTIVITY_CLEAR_TOP,则会调用 onCreate.

Note : If you use only FLAG_ACTIVITY_CLEAR_TOP, then onCreate will be called.

这篇关于如何在没有调用 onCreate() 的情况下返回第一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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