Android的Intent.FLAG_ACTIVITY_SINGLE_TOP和Intent.FLAG_ACTIVITY_CLEAR_TOPIntent、Android、FLAG_ACTIVITY_C

2023-09-04 23:18:59 作者:心易暖亦会涼

我有我已经运行的媒体播放器的应用程序,我想从我的应用家庭活动重新开始活动。

I have an app that I have running a media player and I want to resume the activity from my apps home activity.

我可以通过添加下面的参数传给startActivity呼叫成功地做到这一点:

I can successfully do this by adding the following flags to the startActivity Call:

myIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

我很担心,这不是一个理想的方式做的事情,因为我花了很长时间才找到它。这让我觉得没有人使用它非常喜欢。

I am worried that this is not an ideal way to do things since it took me a long time to find it. It made me think that no one uses it very much.

有什么陷阱,以使用这种方法?

Are there any pitfalls to using this method?

推荐答案

只是为了确保我正确地理解你的问题:假设您的活动堆栈是像A - > B - > C,而现在从C要清除堆栈并返回到A。

Just to make sure I understand your question correctly: Say your activity stack is something like A -> B -> C, and now from C you want to clear the stack and get back to A.

如果这是你想要的,那么这些意图的标志是正确的,应该按预期工作,具体根据的 Android的开发者文档。

If this is what you want, then those intent flags are correct and should work as expected, as per the Android-developer docs.