Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Optimizing memory usage

OP LinuxForce

4th July 2014, 08:46 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
6 posts
Join Date:Joined: Mar 2014
More
Hi !

I'm developing me first "real" (some minor projects before) app for android. Right now i'm trying to optimize the memory usage, regarding to this I have a question. I hope someone can help me.

I've implemented a foreground service, which also updates some UI-elements via a static reference of the MainActivity.

My question is, what happens if the UI is not visible (i.e. MainActivity is destroyed) ? Are these calls ignored ? Are they using memory ?

Thanks in advance!
Last edited by LinuxForce; 4th July 2014 at 10:15 PM.
5th July 2014, 12:39 AM   |  #2  
Member
Thanks Meter: 3
 
36 posts
Join Date:Joined: Feb 2012
You shouldn't keep reference objects with short lifecycle from an object with long lifecycle, unless you carefully manage these references.
To answer your question: UI-elements will be kept in memory till ClassLoader will be destroyed or the references will be nullified.
The Following User Says Thank You to surlac For This Useful Post: [ View ]
9th July 2014, 05:09 AM   |  #3  
Junior Member
Thanks Meter: 0
 
11 posts
Join Date:Joined: Jul 2014
Quote:
Originally Posted by LinuxForce

Hi !

I'm developing me first "real" (some minor projects before) app for android. Right now i'm trying to optimize the memory usage, regarding to this I have a question. I hope someone can help me.

I've implemented a foreground service, which also updates some UI-elements via a static reference of the MainActivity.

My question is, what happens if the UI is not visible (i.e. MainActivity is destroyed) ? Are these calls ignored ? Are they using memory ?

Thanks in advance!

Once the activity is destroyed there should be no more running resources, ie. memory usage. If you want to stop other UI-elements such as lingering toasts or dialogs, you can overwrite the onDestroy method to do so.
5th August 2014, 06:23 AM   |  #4  
Member
Thanks Meter: 3
 
36 posts
Join Date:Joined: Feb 2012
Quote:
Originally Posted by bbish937

Once the activity is destroyed there should be no more running resources, ie. memory usage.

What if class has static reference to one of Views, will it be nullified by itself once the Activity destroyed or it will be kept in memory?
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes