The android app runs in android OS, and Android OS provides a lot of functions for your app to use. So master android architecture can give you a clear overview of what you are doing, what other services and components android OS can provide, and which library should you use when you need it.
1. Android Architecture.
- From the below picture, we can see that there are 4 layers in android. They are Linux Kernel, Android Libraries, Application Framework, Application.
- Linux Kernel: Android OS is developed based on Linux, but it only uses the kernel of Linux OS, so all the java code will be translated to C++ code to run in the Linux kernel layer. The Linux kernel layer will manage all low-level physical components drivers as described in the picture.
- Android Libraries: This is the second layer in the android architecture. It exposes some basic android java libraries to the developer to use. In android app development, most android java libraries that we used exist in this layer. All the library is executed in the android runtime environment. And the library java byte code will be translated to C++ code by the Dalvik virtual machine and then executed in the Linux kernel. We will introduce all the basic android libraries later.
- Application Framework: This layer is a step further from the android libraries layer. It provides some basic android services that android apps can use. Each service reflects one android concept, so this layer makes android app development easy.
- Application: This is the top layer in the architecture. It is just what we developed. So now you should know what are you doing.
2. Fundamental Android Library List.
- As an android developer, you had better know the basic android libraries that OS provides. This can help you to find the library that you need quickly and accurately. Below we will list all the key android packages that are used frequently.
- android.app: This package contains all the classes ( android.app.Application, android.app.Activity, android.app.Service ) and interfaces that used to access application-level component, all other application ( you developed ) is based on it ( extends android.app.Application ).
- android.content: Provide object ( such as android.content.Context, android.content.Intent) which is used to transfer data between applications.
- android.database: Includes classes to consume data from content provider ( android.database.DataSetObserver, android.database.Cursor, android.database.CursorWindow) and also contains sqlite database management classes ( android.database.DatabaseUtils, android.database.sqlite.SQLiteDatabase, android.database.sqlite.SQLiteException ).
- android.graphics: Contains canvases, colors, filters, points, rectangles classes to draw low-level 2D graphics (android.graphics.Bitmap, android.graphics.Canvas, android.graphics.Color, android.graphics.Paint, android.graphics.drawable.BitmapDrawable, android.graphics.Matrix).
- android.hardware: Contains classes that can access hardware such as light sensors and accelerometers.
- android.media: Contains audio and video management classes ( android.media.MediaPlayer, android.media.AudioManager).
- android.net: Contains classes to implement network operations. Such as android.net.Uri, android.net.ConnectivityManager, android.net.NetworkInfo.
- android.os: Used to access android OS services, such as async task ( android.os.AsyncTask ) system environment ( android.os.Environment ), messages ( android.os.Message ) and data bundle ( android.os.Bundle ), etc.
- android.opengl: OpenGL 3D graphics rendering java classes.
- android.print: Provide classes which help android application to print content to configured printers.
- android.provider: Contains classes that used to access data from content provider such as phone contact, calendar ( android.provider.MediaStore, android.provider.Settings).
- android.text: Contains classes used to render and operate text in android screen ( android.text.TextUtils, android.text.TextPaint, android.text.style.ReplacementSpan, android.text.SpannableString, android.text.Html, android.text.Editable)
- android.util: Utility classes to perform some common tasks, such as logging ( android.util.Log ).
- android.view: Contains basic classes used to create android UI and response UI event ( android.view.View, android.view.ViewGroup, android.view.LayoutInflater, android.view.KeyEvent, android.view.MotionEvent ).
- android.webkit: Provides classes to enable web-browsing capabilities in android app ( android.webkit.WebView, android.webkit.WebSettings, android.webkit.URLUtil, android.webkit.WebViewClient, android.webkit.WebResourceRequest ).
- android.widget: Includes mostly used built-in basic ui components such as text view, labels, buttons, list view, checkbox, radio button, layout manager etc ( android.widget.TextView, android.widget.Button, android.widget.EditText, android.widget.ListView, android.widget.LinearLayout, android.widget.TableLayout ).
3. Application Framework.
- The android application framework provides the below services, these services are high-level than libraries, each service is used to control a module of android.
- Activity Manager: Controls android activity lifecycle and stack.
- Content Providers: Enable the android app to share data with each other.
- Location Manager: Provide location service to let the android app get device location data.
- Notifications Manager: Enable the android app to send notifications to the OS to display at the screen top area.
- Package Manager: Android app can use this service to find out other app information installed on the same device.
- Resource Manager: Manager to get resources defined in resource files such as string resource, color resource, and layout resource files.
- Telephony Manager: Provides telephony information such as subscriber and status.
- View System: This contains a lot of classes to manage the app user interface.