[英]What happens to references to an activity after it has been destroyed by the Android OS?
In my app, I need to keep a reference to certain activities, so that I can invoke one of their methods on an asynchronous event (web result) no matter which activity I'm currently ruining. 在我的应用程序中,我需要保留对某些活动的引用,以便无论我当前正在破坏哪个活动,都可以在异步事件(网络结果)上调用其方法之一。 Lets say the activity is in the background, and the system needs resources and destroys my activity. 可以说活动处于后台,并且系统需要资源并破坏了我的活动。
First off, is my instance of the activity completely de-allocated from heap? 首先,我的活动实例是否已从堆中完全取消分配?
does the fact that I have a reference to that activity effect weather or not the systems destroys my activity? 我引用该活动的事实会影响天气,还是系统不会破坏我的活动?
if the activity IS completely wiped from the heap, now I have a non-null reference to an activity instance which points to an un-allocated place in memory which seems very dangerous, so I imagine I should check to see if my reference to the activity points to a valid instance; 如果从堆中完全清除了活动,那么我现在有一个非空引用,它指向一个活动实例,该实例指向内存中未分配的位置,这看起来非常危险,因此我想我应该检查一下是否对我的引用进行了引用。活动指向有效实例; how would I do this? 我该怎么做?
I need to keep a reference to certain activities, so that I can invoke one of their methods on an asynchronous event (web result) no matter which activity I'm currently ruining 我需要保留对某些活动的引用,以便无论我当前正在破坏哪个活动,都可以在异步事件(网络结果)上调用其方法之一
Please use an event bus ( LocalBroadcastManager
, greenrobot's EventBus, Square's Otto, etc.). 请使用事件总线( LocalBroadcastManager
,greenrobot的EventBus,Square的Otto等)。 Please do not "keep a reference to certain activities". 请不要“保留对某些活动的引用”。
Lets say the activity is in the background, and the system needs resources and destroys my activity. 可以说活动处于后台,并且系统需要资源并破坏了我的活动。
This never happens. 这永远不会发生。 Android terminates processes due to low memory conditions; Android因内存不足而终止进程; it does not destroy individual activities due to low memory conditions. 由于内存不足,它不会破坏个人活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.