Processing segments in Android

A game is basically an application in terms of functionality. Multiple applications or games can run on an Android platform. However, for games, only one game is active at one point of time, but rest of the applications run in the background.

Let's have a look at how Android processes its applications.

Application priority

Android sets the priority of the running applications, and it can kill a running application of low priority depending on the requirement.

Each application uses some memory and processing bandwidth. There may be a situation where multiple applications are running together. If a new application wants to run, then Android allocates memory and process bandwidth for the new application. If there is not enough bandwidth or process available, then Android kills one or more than one running application with low priority.

Android sets priority by the following status:

  • Active process
  • Visible process
  • Active services
  • Background process
  • Void process
    Application priority

Active process

An active process is basically a process that communicates with the platform very frequently and runs in the foreground. This process is the last one to be killed by Android, when necessary.

An active process fulfils the following criteria:

  • It runs in the foreground
  • It is visible
  • At least one Android activity is running
  • It interacts actively with the user interface
  • All event handlers are in the active state

Visible process

This process is basically an active process that is not in the foreground and does not interact with the user interface. It is the second highest priority for the Android platform.

The criteria for this process are as follows:

  • It runs in the background
  • It has visible activity
  • It does not interact with the user interface
  • UI event handlers are not active
  • Process event handlers are active

Active services

Active services are services that support an ongoing process without a visible interface. Android will kill such services first and then the actual active process.

This service follows the following criteria:

  • It has no visible interface
  • It supports or works for respective active processes
  • It runs in the background

Background process

Background processes are basically minimized or inactive processes. These processes are not visible on the screen. The process thread does not run for these processes, but the application state is saved in the memory. These are vulnerable to being killed by the processor. These processes can be resumed after interruption.

These are inactive/minimized processes. They remain in memory. The application stays in the paused state.

Void process

Void processes are also called empty processes. A void process is literally empty. It holds no application data or state in memory. This process has the highest priority in order to get killed by the operating system.

Application services

Android application services are parts of the actual application process. These services may run within and outside the parent process.

Let's clear two very common misconceptions about services:

  • A service is not a separate process
  • A service is not a thread

The fact is, services are part of an application process and not separate processes. Services are not threads. They are part of the process that runs in the background, and they keep running even if the main application is in a suspended state.

Services are meant to carry out a single task and do not call back the parent application. This is why they can run even after the application is closed.

Service life cycle

Services are started by the parent application process, as follows:

Context.startService();

After being started, the service starts carrying out a single task in the background. The service can stop itself after the task is done. For example, a simple file download service will stop after a successful downloading task. Many game developers use such features in their games to improve the user experience.

These services can be bound with one or more processes for interactivity. The application can send request and get response from a bound service, which creates a server-client architecture. But these bound services have a limited lifetime until the last application component is bound with the service.

Resource processing

Android has its own resource process structure. It has some predefined resource types:

  • Drawable resources
  • Layout resources
  • Color resources
  • Menu resources
  • Tween animation resources
  • Other resources

Drawable resources

All drawable resources fall in this category, including frame animation. Android provides the res/drawable/ project path dedicated to all drawable resources. All bitmaps, various XML, and predetermined frame animations can be placed here.

These can be accessed through the R.drawable class.

Layout resources

All defined layouts fall in this category. Android provides the res/layout/ project path dedicated to all layout files. Layout is useful to define the application UI.

These can be accessed through the R.layout class.

Color resources

Color resources are basically a list of colors that are due to change upon changing the view of the applicable object. Android stores this in the res/color/ folder in the hierarchy.

These can be accessed through the R.color class.

Menu resources

All menu contents can be defined here. Android provides the res/menu/ project path dedicated to all drawable resources.

These can be accessed through the R.menu class.

Tween animation resources

All tween animation resources fall in this category. Android provides the res/anim/ project path dedicated to all tween animation resources.

These can be accessed through the R.anim class.

Other resources

All other resources are places in the res/values/ folder. Many developers define the string under this category with styles.

These can be accessed through the R.values class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.141.115