简体   繁体   English

Android使用Intent标志启动新的Activity

[英]Android launching new Activity with Intent flags

I'm trying to figure out a way to bring an existing activity to the front and clear all other activities. 我正在尝试找出一种将现有活动放在最前面并清除所有其他活动的方法。 I think I can do this with Intent.setFlags(int flags) but I'm not certain which flags to use. 我想我可以使用Intent.setFlags(int flags)来做到这一点,但我不确定要使用哪个标志。

intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT|Intent.FLAG_ACTIVITY_CLEAR_TOP);

I would think this would work, but it doesn't. 我认为这会起作用,但是不会。 It clears all activities including the one I'm trying to bring to the front. 它清除了所有活动,包括我要带到前台的活动。 Is there a way to do this without clearing the activity I'm trying to bring to the front? 有办法做到这一点而又不会清除我想带给前台的活动吗?

You should use these flags 您应该使用这些标志

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));

It will clear the activity hierarchy and then create your new one. 它将清除活动层次结构,然后创建新的活动层次结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM