Android
each app is a different linux user
each app is assigned a single ID which is given permissions to access only the files within the app
every app runs a single process in it's own virtual machine. Two apps may share the same id and access each other's files if they reside in the same virutal machine.
Glossary
System: the android operating system. Think of this as an entity that orchestrates everything on the phone. The system is the conductor for the whole orchestra. He makes sure the phone stays alive, the phone shows what the user wants to see at almost all costs, apps don't interfere with eachother, etc...
App Component: an entry point through which the system, a user, or another app can enter your app. Activities, Services, Broadcast receivers, Content providers
Activity: entry point for the user. represents a single screen with a single UI. Keeps track of what is on screen. Knows about recently previously used processes and keeps those around. Helps the app handle being killed. Provides a way to smoothly flow from/to another activity.
Service: entry point to keep an app running in the background. no UI. different categories of service. Started Services run and should be kept alive until they complete. some started services are known by the user. keep those around. some are unknown by the user. these may be killed and restarted at a later date. Bound Services provide some API's that others may use. A bound service is a dependency of some other component.
Broadcast Receiver: enables the system to deliver events to the app outside of a regular user flow. After being registered with the broadcast system, a broadcast receiver can hear broadcasts. Broadcasts can be from the system or from another app.
Content Provider: manages a shared set of app data. a content provider exposes data to apps which have permission to acces that data. e.g. contacts info. data is exposed via a URI.
NOTE: Because the system runs each app in a separate process with file permissions that restrict access to other apps, your app cannot directly activate a component from another app. However, the operating system can activate a component in another app. To do this, deliver a message to the system; this message specifies your intent to start a particular component. The system then activates the component for you.
Intent: an asynchronous message used to activate another component. intents bind components to eachother to form some kind of flow. for activities and services, intents define an action to perform e.g. to view or send something. for broadcast recievers, intents define the announcement being broadcast. NOTE: content providers are not activated by intents. They are activated when targeted by a request from a content resolver.
manifest file: All components are declared in this xml file. located in the project root. Defines the permissions, requirements, the dependencies, of your app.
res folder: stands for 'resources'. contains all the images, layouts, audio, video, styles, colors, etc.. for your app. every file in this folder gets a unique integer id which you can reference from your code and from other resources.
fragment: a piece of an application's user interface or behavior that can be placed in an Activity. seems like a way to modularize sections of the UI (kinda like vue/react components). Interaction between fragments is through the FragmentManager
.
UI Thread: the main thread of your application. This thread is in charge of actually drawing the stuff to the screen (hence`, UI thread). Don't block this thread.
Widget: a widget is a UI element which I can create and use in my app. Synonymous with something that extends the View
class.
Lifecycles
Activity Lifecycle

Which processes should be killed? Processes are categorized by priority. Priority is based on these criteria:
what does the phone need to stay alive? If something is threatening the critical functions of the phone (e.g. staying powered on, having enough memory for the os, etc…), it is killed. Chop off the arm to save the body.
What will negatively impact the user experience the most? Try to keep components alive which the user is aware of or actively using. Chop off the finger to save the arm.
Processes can inherit or lose priority: if process A depends on process B and process A is high priority, then process B is upgraded to also be high priority. If background process C has been running for a long time, then it could be downgraded to a lower priority.
foreground processes are required for what the user is currently doing.
visible processes are doing work which the user is currently aware of, and killing it would cause a noticeable negative user experience.
service processes are not visible but they are doing some relatively important things like network data up/downloading
cached processes are not currently needed and may freely be killed.
Fragment LifeCycle
onAttach(Activity)
called once the fragment is associated with its activity.onCreate(Bundle)
called to do initial creation of the fragment.onCreateView(LayoutInflater, ViewGroup, Bundle)
creates and returns the view hierarchy associated with the fragment.onActivityCreated(Bundle)
tells the fragment that its activity has completed its ownActivity#onCreate
.onViewStateRestored(Bundle)
tells the fragment that all of the saved state of its view hierarchy has been restored.onStart()
makes the fragment visible to the user (based on its containing activity being started).onResume()
makes the fragment begin interacting with the user (based on its containing activity being resumed).onPause()
fragment is no longer interacting with the user either because its activity is being paused or a fragment operation is modifying it in the activity.onStop()
fragment is no longer visible to the user either because its activity is being stopped or a fragment operation is modifying it in the activity.onDestroyView()
allows the fragment to clean up resources associated with its View.onDestroy()
called to do final cleanup of the fragment's state.onDetach()
called immediately prior to the fragment no longer being associated with its activity.
Threading
There are simply two rules to Android's single thread model:
Do not block the UI thread
Do not access the Android UI toolkit from outside the UI thread
Intents
An intent is a message sent to the system. This message represents an action to take. Remember, the system is the orchestrator. The system chooses where to send the intent next.
3 Fundamental use cases:
Starting an Activity -
startActivity(intent)
,startActivityForResult(intent)
Starting a Service -
startService(intent)
,bindService(intent)
(this syntax is deprecated, use JobScheduler)Delivering a broadcast -
sendBroadcast(intent)
,sendOrderedBroadcast(intent)
,sendStickyBroadcast(intent)
Intent Types
Explicit: explicitly indicates which app will satisfy the intent.
Implicit: declares a general action to perform which capable apps can 'bid' for. The capabilities of an app are described in each app's manifest file using intent filters. When the system recieves an implicit intent, it polls every app for it's intent filters and shows the user a list of only the apps which can satisfy the intent.

What's in an Intent?
Component Name: optional; the fully qualified name of the component to start; this is what makes an intent explicit
Action: the generic action to perform; customizable, but usually use predefined actions
Data: the URI which references the data to be acted on; also includes the MIME type of the data
Category: additional info about the kind of component that should handle the intent
Extras: extra key-value pairs which might be required or helpful in accomplishing the action
Views/Layouts/Resources

Last updated
Was this helpful?