ik024
ik024

Reputation: 3594

How does Android manages memory?

I was looking into this topic as I wanted to learn more. So I found out the following stuff:

The Android OS gives importance to our app based on the following factors:

  1. Foreground Process - onResume() when we are interacting with the UI of the an app. (Highest Importance)
  2. Visible Process - onPause() when some dialog comes above an app which we are currently using.
  3. Service Process - No interaction with UI but there a service running best eg MP3 player.
  4. Background Process - No UI interaction but there is a thread trying to download an image.
  5. Empty Process - No active components(Activity, Service, Content Provider or BroadCast Receiver) in the process. (Lowest Importance - will be the first one to be removed from memory)

I have to give a seminar for this topic, it goes without saying that I need to give example for each of the above 5 cases.

I am having a hard time for coming up with an example for Background Process.

So for an app to be categorized as Background Process by the Android OS then there should not be any interaction with the user and a thread should be running.

The thing is I am not able to come up with a proper convincing example for Background Process.

Can some one help me out ?

Edit (Only for those people who think this topic is not related in any way to memory management)

This is how Android OS assigns memory to app (if there is not enough memory) by removing app based on above categories, I believe it comes under memory management.

Upvotes: 4

Views: 380

Answers (2)

ianhanniballake
ianhanniballake

Reputation: 200130

As explained in this Android blog post, a background process:

  1. Does not qualify as a foreground, visible, or service process (i.e., no visible activities, no running services)
  2. Contained a previously foreground/visible activity

At this point, the process is considered a background process. It has nothing to do with whether a thread is running or not - the process could certainly not be doing anything at all. In fact, the only difference between an empty process and background process is the previously active activity. In both cases, these processes are kept around primarily for caching purposes and can be killed at anytime.

Upvotes: 0

Umair Khan
Umair Khan

Reputation: 193

Android Async task is an example of background process. It is also synchronized with the main UI thread. doInBackground() method of async task does the background processing (no UI interaction) but its methods like onPreExecute() and onPostExecute() can interact with the UI.

Example: You want download an image, initialize the image view in onPreExcute(), download processing goes to doInBackground() method and display the downloaded image on image view in onPostExecute().

Upvotes: 1

Related Questions