- Android Development Tutorial
- Android Core Concepts
- Installing Android Studio
- Your First Android App
- Android Project Overview
- Android Activity
- Android View and ViewGroup
- Android Layout
- Android Fragment
- Android ActionBar
- Article TOC Test
- Android Toast
- Android TextView
- Android Buttons
- Android Web Apps Using Android WebView
Android Core Concepts
This text gives you an overview of the Android core concepts. Having a basic understanding of Android's core concepts will make it easier for you to dive into the various different topics.
Apps and APK Files
An Android app is an Android application. An app is packaged in an APK file (Android application package). The APK file contains the compiled Java code and other resources like texts and images for the Android application.
An Android activity is a GUI component. It corresponds roughly to a window in a desktop application. Since mobile phone screens are small, an activity typically takes up the whole screen. If you open multiple activities they are stacked on top of each other. You cannot arrange activities side by side, like you can do with desktop windows.
These two screenshots show an Android app with a list of websites. If you click on any of the websites in the list, the website will open in a new activity which takes up the whole screen. If you click the "back" button on your Android device, you will be taken back to the first activity with the list of websites.
In Android a fragment is a fragment of a total user interface. A fragment typically only takes up part of the screen. Fragments are used inside activities. Fragments can be reused within different activities.
Fragments typically contains Views and ViewGroups inside them.
Views and ViewGroups
Android GUI elements fall into three categories: Activities, Views and ViewGroups. Activities are the screens / windows. Views are the individual GUI elements, like a TextView displaying a text, a Button that users can click on etc. ViewGroups are containers for Views. A ViewGroup groups a collection of Views together.
Views and ViewGroups can be nested inside an activity or inside a fragment (which is again nested inside an activity).
Layout XML Files
Activities, fragments and some ViewGroups can use XML files to define their layout and contents. The layout XML files specify what GUI components an activity or fragment contains, as well as styling of the GUI components (size, margins, padding etc.).
Android intents are small objects that an activity can pass to the Android operating system, to tell the operating system that some other action or actvity is required. For instance, a photo app may send an intent to the operating system when the user has chosen to share a photo. The intent describes the "sharing action". Other applications that knows how to perform the "sharing action" can then be opened, and the sharing can be performed via another application.
Intents can also be used to open a new activity (screen) from an already visible activity, inside the same application. These screenshots illustrates that:
These screenshots show two activities in the same Android app. The first activity opens the second activity via an intent object.
Android widgets are GUI components which can be displayed outside of an activity. For instance, a weather widget showing todays weather is shown on many Android home screens. Widgets are implemented and packaged as part of an Android application.
Sometimes Views in Android are also referred to as "widgets". For instance, many of the GUI components (View subclasses)
are located in a Java package called
android.widget . But, GUI components are not the same as a
widget which can live on the home screen of an Android device. So, be careful when you read about Android to
make a distinction between GUI components which can be used inside ViewGroups, Fragments and Activities (and
also inside Widgets), and Widgets which can live on the home screen of the Android device.
This is a screenshot of a home screen on an Android device. Notice the weather widget at the top of the home screen.
Android services are background processes that can be executed on an Android device, even if no application is visible. Services do not need a user interface. A service could for instance check a remote server for updates, or backup data every hour etc.
Android devices typically have a set of sensors built in which you can access from your Android applications. For instance, the built-in GPS in many smart phones is a sensor. Thus, you can get access to the GPS from inside your Android applications.