Android App Development Fundamentals for Beginners

Android is an operating system which is build basically for Mobile phones. It is based on the Linux Kernel and other open sources softwares and is developed by Google. It is used for touchscreen mobile devices such as smartphones and tablets. But nowadays these are used in Android Auto cars, TV, watches, camera,etc. It has been one of the best-selling OS for smartphones. Android OS was developed by Android Inc. which Google bought in 2005. Various applications (apps) like games, music player, camera, etc. are build for these smartphones for running on Android. Google Play store features more than 3.3 million apps. The app is developed on an application known as Android Studio. These executable apps are installed through a bundle or package called APK(Android Package Kit).

Android Fundamentals

  • Android Programming Languages : In Android, basically programming is done in two languages JAVA or C++ and XML(Extension Markup Language). Nowadays KOTLIN is also preferred. The XML file deals with the design, presentation, layouts, blueprint,etc (as a front-end) while the JAVA or KOTLIN deals with working of buttons, variables, storing, etc (as a back-end).
  • Android Components :The App components are the building blocks of Android. Each components have their own role and life-cycles i.e from launching of an app till the end. Some of these components depend upon other also. Each component have a definite purpose.

    The four major app components are:

    1. Activities : It deals with the UI and the User interactions to the screen. In other words, it is a User Interface that contains activities. These can be one or more depending upon the App. It starts when the application is launched. Atleast one activity is always present which is known as MainActivity.

      The activity is implemented through the following Syntax:



       public class MainActivity extends Activity{
        // processes
      }
      
    2. Services : Services are the background actions performed by the app, these might be long running operations like a user playing music while surfing the Internet. A service might need another sub-services so as to perform a specific tasks. The main purpose of the Services is to provide non-stop working of the app without breaking any interaction with the user.
      Syntax:

        public class MyServices extends Services{
        //code for the services
      }
      
    3. Broadcast Receivers : A Broadcast is used to respond to the messages from other applications or from the System. For example, when the Battery of the phone is low, then the Android OS fires a Broadcasting message to launch Battery Saver function or app, after receiving the message the appropriate action is taken by the app. Broadcast Receiver is the subclass of BroadcastReceiver class and each object is represented by an Intent objects.

      Syntax:

      public class MyReceiver extends BroadcastReceiver{
         public void onReceive(context,intent){
         }
      
    4. Content Provider : Content Provider is used to transfer the data from one application to the others on request of the other application. These are handled by the class ContentResolver class. These class implements a set of APIs(Application Programming Interface) that enables the other applications to perform the transactions. Any Content Provider must implement the Parent Class of ContentProvider class.

      Syntax:

      public class MyContentProvider extends ContentProvider{
         public void onCreate()
         {}
      }
      
  • Structural Layout Of Android Application

    The above figure represents the various structure of an app.

    1. Android Mainfest is a XML file which is the root of the project source set. It describes the essential information about the app and the Android build tools, the Android Operating System and the Google Play. It contains the permission that an app might need in order to perform the specific task. It also contains the Hardware and the Software features of the app, which determines the compatibility of an app on Play Store. It also includes the special activities like services, broadcast receiver, content providers, package name,etc.
    2. The JAVA folder consist of the java files that are required to perform the background task of the app. It consist of the functionality of the buttons, calculation, storing, variables, toast(small popup message) , programming function, etc. The number of these files depends upon the type of activities created.
    3. Res or Resource folder consist of the various resources that are used in the app. This consist of sub-folders like drawable, layout, mipmap, raw and values. The drawable consist of the images. The layout consist of the XML files that defines the user interface layout. These are stored in res.layout and are accessed as R.layout class. The raw consist of the Resources files like audio file or music file,etc. These are accessed through R.raw.filename. values are used to store the hardcoded strings(considered safe to store string values) values, integers and colors. It consist of various other directories like:-
      • R.array :arrays.xml for resource arrays
      • R.integer : integers.xml for resource integers
      • R.bool : bools.xml for resource boolean
      • R.color :colors.xml for color values
      • R.string : strings.xml for string values
      • R.dimen : dimens.xml for dimension values
      • R.style : styles.xml for styles
    4. Gradle: Gradle is an advance toolkit, which is used to manage the build process, that allows to define the flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app. The Android plugin for Gradle works with the build toolkit to provide processes and configurable settings that are specific to building and testing Android applications. Gradle and the Android plugin run independent of Android Studio. This means that you can build your Android apps from within Android Studio. The flexibility of the Android build system enables you to perform custom build configurations without modifying your app’s core source files.

      Basic Layout Can be defined in tree structure as:

      Project/
         app/
            manifest/
               AndroidManifest.xml
         java/
            MyActivity.java   
            res/
               drawable/  
                  icon.png
                  background.png
               drawable-hdpi/  
                  icon.png
                  background.png  
               layout/  
                  activity_main.xml
                  info.xml
               values/  
                  strings.xml 
      
  • Lifecycle of Android App

    The Lifecycle of the Android App can be shown through this diagram:

    States of Android Lifecycle

    1. OnCreate : This is called when activity is first created.
    2. OnStart : This is called when activity become visible to the user.
    3. OnResume : This is called when activity starts to interact with the user.
    4. OnPause : This is called when activity is not visible to the user.
    5. OnStop : This is called when activity is no longer visible.
    6. OnRestart : This is called when activity is stopped, and restarted again.
    7. OnDestroy : This is called when activity is to be closed or destroyed.

To know more about Android Click :Here
To know about the Installation and Setup Click :Installation



My Personal Notes arrow_drop_up

Loves Coding##

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

7


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.