开始新活动时删除旧的活动实例 [英] Delete old activity instance when starting a new activity

查看:91
本文介绍了开始新活动时删除旧的活动实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个(具有相同活动的)新实例时,我希望删除/删除一个旧的活动实例,但是我需要将所有其他活动保留在后栈中(因此FLAG_ACTIVITY_CLEAR_TOP不够用).

I'm looking to delete/remove an old activity instance when a new instance (of same activity) is created, however I need to maintain all other activities in back-stack (therefore FLAG_ACTIVITY_CLEAR_TOP won't suffice).

例如说我有活动A,B和C. 我开始:A-> B-> C->B. 在第二个B活动开始时,我需要删除现有的B活动. 因此,我现在有:A-> C-> B正在运行...

E.g. say I have activities A, B & C. I start: A -> B -> C -> B. On the start of the second B activity I need to remove the existing B activity. Therefore I now have: A -> C -> B running...

任何帮助表示赞赏.

推荐答案

删除活动似乎并不像我想象的那么容易,因此,这不是一个完整的答案,但我将继续使用FLAG_ACTIVITY_REORDER_TO_FRONT.这不会杀死现有活动,而是将其移到堆栈顶部.

It seems that deleting the activity is not as easy as I would have imagined therefore not a complete answer but I'm going to go with using FLAG_ACTIVITY_REORDER_TO_FRONT. This will not kill the existing activity but instead move it to top of stack.

Intent intent = new Intent(ctx, Activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

这将允许上面概述的活动导航.

This will allow for the activity navigation outlined above.

如果有人知道清除实际活动的方法,我仍然很感兴趣.

I'm still interested if someone knows of a means to clear the actual activity.

这篇关于开始新活动时删除旧的活动实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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