做演员意图都被删除? [英] Do Intent extras have to be removed?

查看:118
本文介绍了做演员意图都被删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但有,指出意图演员必须由消耗活动被明确删除,或者如果你回收意向的对象是,只有真的吗?规则

This might be a stupid question, but is there a rule that states that intent extras have to be explicitly removed by the consuming activity, or is that only true if you're recycling Intent objects?

换句话说,如果我一直链到下一个活动做类似:

Put another way, if I always chain to the next activity by doing something like:

Intent i = new Intent(MyCurrentActivity.this, FooActivity.class);
i.putExtra("first", "stringvalue");
i.putExtra("second", 69L);
startActivity(i);

然后在FooActivity,我读他们回来了...

then, in FooActivity, I read them back out...

String first = getIntent().getStringExtra("first");
long second = getIntent().getLongExtra("second");

...我必须也明确删除它们,以避免意外污染未来活动的意图,或者从我完成他们抓住的那一刻,我可以忘记他们甚至还存在,继续前进?

... do I have to also explicitly remove them to avoid accidentally polluting a future activity's intent, or from the moment I finish grabbing them, can I just forget they even exist and move on?

我可以发誓,我记得读的东西,说我不得不删除他们,但我一直没能再次找到它,我怀疑这可能只适用于重复使用意向的对象。

I could swear I remember reading something that said I had to remove them, but I haven't been able to find it again, and I'm suspecting that it might only apply to reused intent objects.

推荐答案

如果你打算使用相同的Intent对象,但不需要(也不需要)的额外内容,那么你可以删除它们。相反,如果你想调用start与同演员一样的意图,然后留住他们。最后,如​​果该对象将被破坏,谁在乎的演员?

If you're planning to use the same Intent object but do not need (nor want) the extras, then you may remove them. If, instead, you want to call the start the same intent with the same extras, then keep them. Lastly, if the object is going to be destroyed, who cares about the extras?

在任何情况下,我决定调用者的活动,而不是意图的接收器。

In any case, I would decide on the caller activity, not on the receiver of the intent.

这篇关于做演员意图都被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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