In android wh have 4 components:<activity>, <service>, <receiver>, and <provider>

in manifest they all have a android:process attribute to say in which context its running

The <application> element also supports an android:process attribute, to set a default value that applies to all components.


Each app process is forked from an existing process called Zygote. The Zygote process starts when the system boots and loads common framework code

Memory management: every app is dedicated a Virtual Page Memory which can grow up , but limited to a level by System (Dalvik)and not more!!!!if it reachs a max capacity and require more memory it recive

 OutOfMemoryError,in your app you can verify the size of heap available for you by  int getMemoryClass()

return is integer og megabayte , by setting  largeHeap attribute to your manifest your heap will be latger!

LRU:cache for apps least used

When you start a service, the system prefers to always keep the process for that service running!

so LRU is reduced to less process,The best way to limit the lifespan of your service is to use an IntentService which finishes itself as soon as it's done handling the intent that started it

To be notified when the user exits your UI, implement the onTrimMemory() callback in your Activity classes. You should use this method to listen for the TRIM_MEMORY_UI_HIDDEN level, which indicates your UI is now hidden from view and you should free resources that only your UI uses.

Notice that your app receives the onTrimMemory() callback with TRIM_MEMORY_UI_HIDDEN only when all the UI components of your app process become hidden from the user. This is distinct from the onStop() callback, which is called when an Activity instance becomes hidden, which occurs even when the user moves to another activity in your app. So although you should implement onStop() to release activity resources such as a network connection or to unregister broadcast receivers, you usually should not release your UI resources until you receive onTrimMemory(TRIM_MEMORY_UI_HIDDEN). This ensures that if the user navigates back from another activity in your app, your UI resources are still available to resume the activity quickly.[notice this callback is invoked in addition when system is in Low state)

How system works : it has a list of "importance hierarchy"  

In all cases System start killing process in LRU by priority/privileged, those having a service considered to have more privilege so killed at the end ! a process with no UI more likely will be killed before a process with having UI!!!UI is a considered as a privileged ,the following are the privileg level in order of each components inside process

1)when process hosts :service with UI or foreground having (startForeground())

2)when process hosts : generic service with oncreate onstart..

3) when process hosts :background service

4)when process hosts : a BroadCastReceiver

Empty process are often killed!


Limit of 65000 methods in APKs:

Dex file which is a compiled file for Dalvik put index on every method reference including System , library, framework,etc (0x0000 to 0xffff), if the number of methods in your program is more than 65k , your application cannot be compiled with missing index error! in this case there is a solution for OS Android 5 and higher , Dex files in os>=5 supports multidex support library ,you can use the multidex support library, which becomes part of the primary DEX file of your app and then manages access to the additional DEX files and the code they contain.

 Android SDK Build Tools 21.1 and higher supports multidex

[Android 5 and superior, uses a runtime ART which natively supports loading multiple dex files from application APK files. ART performs pre-compilation at application install time which scans for classes(..N).dex files and compiles them into a single .oat file for execution by the Android device]

to support it add in your graddle:

-Change your Gradle build configuration to enable multidex

-Modify your manifest to reference the MultiDexApplication class

-Modify your app Gradle build file configuration to include the support library and enable multidex output, as shown in []

the following Gradle build file snippet:

android {

    compileSdkVersion 21

    buildToolsVersion "21.1.0"

    defaultConfig {


        minSdkVersion 14

        targetSdkVersion 21


        // Enabling multidex support.

        multiDexEnabled true




dependencies {

  compile ''


<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android=""








 © Xosrov 2016