Android的Intent.FLAG_ACTIVITY_SINGLE_TOP和Intent.FLAG_ACTIVITY_CLEAR_TOP [英] Android Intent.FLAG_ACTIVITY_SINGLE_TOP AND Intent.FLAG_ACTIVITY_CLEAR_TOP

查看:288
本文介绍了Android的Intent.FLAG_ACTIVITY_SINGLE_TOP和Intent.FLAG_ACTIVITY_CLEAR_TOP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于Android的Intent.FLAG_ACTIVITY_SINGLE_TOP和Intent.FLAG_ACTIVITY_CLEAR_TOP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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