资产和参考
我想知道是否有一种方法可以从其他类获取活动的引用,而不将其作为参数传递。 特别是,要打开资产,我需要活动调用 getAssets()
,但我没有对该活动的任何引用。
I want to know if is there a way to obtain a reference of an activity, from an other class, without passing it as parameter.
In particular, to open an Asset I need that the activity invoke getAssets()
, but I haven't any reference to the activity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
适当的方法是传递引用。您可以将其作为静态变量存储在某处,但这是一种非常不推荐的方法。如果您没有参考,请考虑更改您的设计。
我并不是说这只是作为一种教育/理论论证,而是来自(糟糕糟糕糟糕)的经验。
The appropriate way is to pass the reference. You can store it as a static variable somewhere, but this is a very unrecommended method. If you don't have a reference, consider changing your design.
I'm not saying that only as an educative / theoretic argument only, but from (bad bad bad) experience.