“不要将Android上下文类放置在静态字段中;这是一个内存泄漏(也打破了即时运行) [英] "Do not place Android context classes in static fields; this is a memory leak (and also breaks Instant Run)"

查看:8256
本文介绍了“不要将Android上下文类放置在静态字段中;这是一个内存泄漏(也打破了即时运行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不要将Android上下文类放在静态字段中;这是一个内存泄漏(也打破了即时运行)显示时,任何Android控件静态。任何更好的方法来访问一个Android控件(如TextView)从其他类,而不是创建一个父类或使它(TextView)静态的对象?

"Do not place Android context classes in static fields; this is a memory leak (and also breaks Instant Run)" is shown while making any Android control static. Any better way to access an android control(like TextView) from other class other than creating an object of Parent class or making it(TextView) static?

推荐答案

我不知道你在做什么是有效的,但你可以使用事件总线,如 Otto 将事件从对象发送到对象(例如从服务到活动)

I'm not sure if what you are doing is valid, but you can use an event bus, such as Otto to send events from objects to objects (such as from a Service to an Activity)

您可以拥有自己的应用程序 -derived对象,这将是一个单一的存在所有的时间,而你的程序是活着的,所以你可以有静态字段。

And you can have your own Application-derived object, this will be a singleton existing all the time while your program is alive, so you can have static fields in there.

这篇关于“不要将Android上下文类放置在静态字段中;这是一个内存泄漏(也打破了即时运行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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