如何在不调用其onCreate()的情况下返回第一个活动 [英] How to come back to First activity without its onCreate() called
问题描述
我有3个活动.活动A,活动B,活动C.这是流A-> B-> C.现在,我想从C进入活动A(即C-> A),而不必获取其名为Activity 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();
推荐答案
两种情况:
-
如果您想继续进行其他活动,并且只想将A放在前面,只需使用意图标记FLAG_ACTIVITY_REORDER_TO_FRONT.
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屋!