Application

An Android app consists of components such as activities, services, broadcast receivers, and content providers, as shown in Figure 2-1. Activities are for interacting with device users, services are for program parts that run without a dedicated user inte

  • PDF / 237,500 Bytes
  • 5 Pages / 504 x 720 pts Page_size
  • 42 Downloads / 135 Views

DOWNLOAD

REPORT


2

Application An Android app consists of components such as activities, services, broadcast receivers, and content providers, as shown in Figure 2-1. Activities are for interacting with device users, services are for program parts that run without a dedicated user interface, broadcast receivers listen for standardized messages from other apps and components, and content providers allow other apps and components to access a certain amount and kind of data provided by a component.

Figure 2-1.  An app in the Android OS

Components get started by the Android Runtime, or execution engine if you like, either by itself or on behalf of other components that create start triggers. When a component gets started depends on its type and the meta-information given to it. At the end of the lifecycle, all running components are subject to removal from the process execution list either because they have finished their work or because the Android OS has decided that © Peter Späth 2018 P. Späth, Pro Android with Kotlin, https://doi.org/10.1007/978-1-4842-3820-2_2

7

8

CHAPTER 2: Application

a component can be removed because it is no longer needed or that it must be removed because of a device resource shortage. To make your app or component run as stable as possible and give your users a good feeling about its reliability, a deeper knowledge of the lifecycle of Android components is helpful. We will be looking at system characteristics of components and their lifecycles in this chapter. Simple apps and Android components are easy to build; just refer to one of the tutorials on the official Android web site or one of the thousand other tutorials elsewhere on the Web. A simple app is not necessarily a professional-level stable app, though, because Android state handling as far as the app is concerned is not the same as for a desktop application. The reason for this is that your Android device might decide to kill your app to save system resources, especially when you temporarily suspend the app in question because you use one or more other apps for some time. Of course, Android will most likely never kill apps you are currently working with, but you have to take precautions. Any app that was killed by Android can be restarted in a defined data and processing state, including most currently entered data by the user and possibly interfering in the least possible amount with the user’s current workflow. From a file perspective, an Android app is a single zip archive file with the suffix .apk. It contains your complete app including all meta-information, which is necessary to run the app on an Android device. The most important control artifact inside is the file AndroidManifest.xml describing the application and the components an application consists of. We do not in detail cover this archive file structure here, since in most cases Android Studio will be taking care of creating the archive correctly for you, so you usually don’t need to know about its intrinsic functioning. But you can easily look inside. Just open any *.apk file