简体   繁体   中英

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.). 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; it does not destroy individual activities due to low memory conditions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM