Structure and Working of Android

 

So far you might have enjoyed developing your First Android App. Now let us explore Structure and Working of Android.

First let us understand how android Applications works

  • When-ever we launch any Android  App, its AndroidManifest.xml is called. From here it checks required permissions, target OS version and explores other information like App version, App icon, default App theme, etc.
  • Then it looks for the launcher Activity(Page) and launches its corresponding Java file. ( In case of our myFirstApp it will launch MainActivity.java )
  • Our Java file ( MainActivity.java ) is linked to XML Layout file ( activity_main.xml ) which contains the User-Interface and other visual components. The Java file invokes this XML Layout file, this is depicted below.

Android Structure - How MainActivity.Java file invokes activity_main.xml

 

Now talking about the Directory Structure of the Projects inside Android Studio.

  • Expand your “MyFirstApp” which we created in our previous tutorial or if you don’t have it then download it and import project into Android Studio. On expanding our project it will look like one shown in the figure below.

Android Structure of Project inside Android Studio

 

Contents & other description for components of Package Explorer :

Component Description
AndroidManifest.xml This is the file which contains main details of our App like application update version, App Icon, App. theme, Package name, name of Activities & Launcher Activity (Activity=Page Of Android), special permissions like File RD/WR permissions, internet permissions, Vibrator permission etc.
MainActivity.java This Java class will contain all our business logic, it will .
‘res’ It contains several files & folders i.e. Resources for the application. We can use it to store images, XML files, color, style, etc.
drawable drawable folder contains – xhdpi , hdpi , mdpi , ldpi images which we use in our App. We should prepare multiple copies of same image in the ratio 2 : 1.5 : 1 : 0.75 respectively. This helps better visual effect on varied screen density-size real devices. This folder also contains some XML files using which we can make custom animations in our App.
Layout It contains our XML layout files containing visual UI items like textViews, Buttons, Check Box, Scrolling containers, etc. You can also develop App supporting Landscape or Portraid mode by creating folder layout-land & layout-port along with layout folder. (This will be covered later)
mipmap mipmap folder also contains – xhdpi , hdpi , mdpi , ldpi images which we use in our App. In-fact out ic_launcher i.e. the app icon is stored here.
values It Contains files like String.xml which contains all String identifier name-value pairs which we use in our App, Style.xml which defines theme of the App, dimension file ,colors.xml, values-v11 & v14 are used to develop support for large screen tablets.
raw By default this is not generated, we can create it separately. It can contains audio files like mp3, mp4, wav, etc. which you can play in media player
Gradle Scripts These scripts contains project related details, which will help build the source code and generate app. build.gradle(Module:app) will contain details like which is minSDK, targetSDK, gradle plugin, app version, dependencies or library used in project, etc.

 

 

Terminologies for Android Entities :

Component Description
Activity Component or Page of Android for composing UI.
Service Component that runs in the background continuously while running another process in front. It doesn’t have visual UI. (It is totally different from concept of Web-Service). e.g. Service playing Media player in background and allows user do another task.
Intent Intent is a messaging element which sends data & action to various Activities or Intents can also be used to invoke new Activity.
Intent Filter Defines component by setting intent for receiving filtered items.
Broadcast Receiver Broadcast Receivers listens to a condition continuously and when the condition is triggered we can respond it through Broadcast Receivers, e.g. battery level goes low, arrival of SMS/eMail, internet connectivity, WiFi connectivity, file received over blue-tooth etc. It doesn’t have visual UI.
Fragments A Fragment represents a behaviour or a portion of user interface in an Activity. You can combine multiple fragments in a single Activity to build a multi-pane UI and reuse a fragment in multiple Activities.
Content Provider Provides standardized interface for sharing data among applications.
Notification Notifying a certain event to user. Like Alarm, Completion of Downloads, Low Battery level.
Toast A Prompt message which can be given to user to guide or to inform him/her, which has property of disappearing after a pre-defined time.

 

Keeping this much for this Tutorial. In next tutorial you will explore the codes of MyFirstApp.

 

Report Errors + Bugs & Become Insider for Nestedif.com

We would like to hear you, if you find any error or misspelled phrase while reading our tutorials. By reporting mistakes through email to insider@nestedif.com you could help other peers.