简体   繁体   English

在Android OS销毁某个活动之后,对活动的引用会如何处理?

[英]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.

相关问题 在创建它的Activity被销毁后,Android线程会发生什么? - What happens to an Android thread after the Activity that created it is destroyed? Android片段-在片段中按文本后,“活动已被破坏” - Android Fragments - “Activity has been destroyed” after pressing text in a fragment 重新创建活动后,表面被销毁 - Surface is destroyed after the activity has been recreated IllegalStateException活动已被销毁错误android - IllegalStateException Activity has been destroyed error android Android:IllegalStateException:活动已被破坏 - Android: IllegalStateException: Activity has been destroyed Android 处理程序在活动被销毁后仍会继续运行一段时间 - Android Handler keeps running for a while even after the activity has been destroyed 活动在fragmenttransaction.commit上已被破坏 - Activity has been destroyed on fragmenttransaction.commit 执行JUnit方法后会发生什么? - What happens after a JUnit method has been executed? 当Activity在其AsyncTask运行时被销毁时,内存中会发生什么? - What happens in memory when the Activity is destroyed while its AsyncTask is running? 选项卡片段错误发生,并且片段父活动已被破坏 - Tab fragment error occurring and fragment parent activity has been destroyed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM