 Hi, good morning all of you, I am Kapil Shemkal Laini, I am a computer science engineer and I am working in Einstein technology from more than 3 years I am working on the android platform. So you can say that I can breathe, I breathe android, I sleep with android. So we are today here to, I am today here to explain you the basics of the android. So let us start. Let me give you the brief introduction to our company. Our company is mainly into embedded and mobile products solutions. We have delivered various mobile applications to client and we are also building some applications for ourselves to launch. We have created an application that actually saves human's life that is an alarm center application. When user is in trouble, user can raise alarm and he will get help from various resources and there is another application that we are creating. It will explain you the how android can be useful in remote areas. In remote areas it is very, it is very, it is very hard that to provide the instruments that cost 2 or more than 2 or 3 lakhs to identify or to detect the malaria in the blurred sample. So we are creating the android application that actually processes the blurred sample and it detects whether it is a malaria or not. These are the contents that today I am going to explain. What is android? The history of android, then android architecture, then android building blocks and android building process and then we will have a question and answer session. So what is android? Yeah, it is very general that it is mobile operating system but it is not 100% true. Yeah, it is operating system that it is a consist of operating system but it is a whole package. It comes with, so in technical terms we call it as a software stack and what software stacks comes up with? It comes up with operating system that is Linux 2.6, then it comes with a middleware that is all the libraries, all APIs, then there are some key applications like email client, phone, SMS and all. It comes with that application and also a rich set of APIs. So one more question, so android is operating system. So is android Linux? The answer is android is not Linux. Android is just based on Linux, android uses Linux kernel 2.6 for its various processes that is for security, for memory management, for process management it uses Linux kernel but it is not Linux. We can say that in Linux there is a native windowing system, we called it as X windowing, it is used for networking, so android does not support that windowing system. Also android does not have a glitzy support, it is a normal GC3 compiler, android that does not support and there are other various utilities like GNU, Linux utilities that android does not support. So what Linux provides to android? So what Linux actually does in android? It provides a security model. In Linux it assigns user IDs to every user and one user cannot access the properties or the data of another user. That security model android uses but it is slightly different context. In android every application has a user ID. So every application runs with a different user ID so that no application can access other applications property. So that security model is from Linux kernel. Also it provides the memory management like paging and all other algorithms, process management, process scheduling, then it also provides a network stack, then various drivers it provides, it also abstracts the hardware from upper layer and as he said android has modified or he introduced some patches into Linux kernel. So what are these? Android has done main thing is alarm. So in mobile it is required that after some time or after given time it will wake up or it will raise an alarm. So that is the alarm that the android has implemented that was not presented in original Linux. Also there is a hash mem that is android shared memory. So in android two more than two applications shares the same memory. So that was not originally present in Linux. And also android runs on the devices where power is a crucial thing and so it also enhance the features to save the power that is the power management techniques it has introduced. Then also android runs on a very limited environment that is there is a low memory low CPU usage. So if a certain condition arise where there is a low memory. So in that case android kills the application which uses vast resources. So that other resources can utilize that and user will have a seamless user experience. And also android has enhanced or implemented a logger functionality. It is just like a system.println but it is used for debugging purpose as you all are aware of locked in android. So where we can see all logs that is a logger. We use android for android development we use the java language. So my next question is android java. Yes we all know it is not the java it just uses java. It just uses to create a program. It also implements the java 5 aces specifications. So what java 5 has provided the apis then all the features that it have implemented. But it does not uses the java virtual machine it uses its own that is dalvik virtual machine. It is highly optimized to run on a very low environment low memory environment. Now let's take a look at the history of android. In 2005 Google has acquired Google acquired android incorporation and it the work on the dalvik virtual machine has begin after that. But two years before the android incorporation has begin by a group of people who had a mission to create a mobile application or to create a mobile operating system. In 2003 and 2005 Google acquired them and the work has started. Then in 2007 Google announced open handset allowance. It is a group it is a group to create a open standard for the mobile platform. And various companies various companies like mobile manufacturers and telecommunication companies are have come together to form that group. The examples are the Samsung LG or we can say T mobile that all are in the open handset allowance. Then later it is Sony Ericsson and other companies have joined that group. So in current situation more than 86 companies are in that group that are working to create open standard. Then in 2008 T mobile announced G1 mobile it is android and released SDK 1.0 and it is also released open source. Then in 2009 cupcake that is the SDK 1.5 released. It is the most stable version than the previous version previous two versions were beta versions. They named as apple pie and banana bread and this is the third one cupcake it comes with the soft keyboard. Then later 1.6 doughnut and 2.0 2.1 that is the Eclare has released. Then in 2010 Nexus 1 mobile released to the market and SDK 2.2 that is a Froyo released. The addition the main feature addition to the Froyo was USB and Wi-Fi tethering and later 2.3 ginger word were added were released ginger the main feature added in the ginger word was NFC support then video calling etc. Then the latest releases are 4.0, 4.1 ice cream sandwich and 3.0, 3.1 that is honeycomb. Honeycomb is for tablet pieces or tablet devices. The UI is designed to suit the tablets. This is the current distribution of the android versions. So we can say that more than 60% is android 2.3 it is distributed in public and then android 2.2 it is near about 40%. So this distribution is important because if you are going to create the applications then we need to understand the target. So this distribution is very important so that we cannot we will not miss users. So this is the android architecture. There are mainly 5 components in the android architecture. The very lower level architecture component is a Linux kernel that we have earlier mentioned. It consists of various drivers. Then the next above layer is libraries. Android provides various libraries for like SQLite, then OpenGL for 3d 2d. Then there is android run time. It consists of various core libraries that is that Java has provided and Google has added some android specific libraries and there is a Dalvik virtual machine. And the next above layer is application framework. As a developer this is the most important framework because it provides all the APIs. And the next layer is application that there all the native applications will reside. And as well as native application all the third party applications will also reside there. And if we create application then it will also be in the same layer. So every application is same. So if there is some built-in application we can replace that application using that framework. So now we will see every component in detail. It is a Linux kernel 2.6. It abstracts the hardware from above layer. It provides as we have already said it provides the security memory process management. And it also provides various device drivers. That is display driver, then camera driver, then Bluetooth driver, keypad driver, whatever drivers that android device required. But it is used from Linux kernel. Then the next layer is native libraries. Android stack includes various libraries like surface manager. Surface manager is used to draw things on the screen like a 3D or drawing the camera on the screen. Then there is a media framework which is used to play a media components on the device. Then there is also SQLite. It provides a built-in database. But it is not like Oracle or SQL. It is a lightweight database. It provides limited access but we can use that to solve our application need. Also there is OpenGL support which we can use it to render 2D, 3D objects. The next component is Android runtime. This component includes two components. That is core libraries and Dalvik virtual machine. So what are the core libraries? We use Java for developing Android applications. So we use ArrayList, we use Generics, we use Interfaces. So it is a Java library. So Android has implemented all the Java features into it as a library. And we use that feature to develop our Android application. But it is not copied as is. Android has changed the features of the Android. So there is no JVM. In general, Java classes get executed on Java virtual machine. But Android has optimized Java virtual machine to run on very low memory or very limited environment. And they have created a Dalvik virtual machine. And here the dot class doesn't run. There is a DEX that is the Dalvik executable the finally which runs on the Dalvik virtual machine. So let us understand what is the exact difference. What is JVM and what is JVM? So it sounds like same. For a developer perspective, there is no difference. We write Java application, it gets executed on the JVM and if we write in Android application it is executed in the JVM. So what is the difference? There is architectural difference between them. If you consider DVM is a registered based. So and JVM is a stack based. So what is registered based? All the Java classes or the Java code get converted into a assembly language code. And to create assembly language code for Dalvik virtual machine it use the register as a primary storage. And whereas in DVM it use the stack as a primary storage. And also DVM is highly optimized. Then it runs DEX file whereas in JVM it runs dot class, dot jar files. And Google claims that it reduces 30% of instruction set as compared to JVM. So this is a notable thing that Android has done. So what exactly happens in creation of the DEX file? We write code in Java then normally it is compiled by Java tool, Java compiler. So from dot Java class it creates dot class file and it is Java byte code. But there is another tool that is the DEX tool which converts dot class file to the DEX file. And here it changed or he optimized Java byte code to the Dalvik byte code. And finally that DEX file get executed on the Dalvik virtual machine. Now this layer is application framework layer. As I have said as a developer every time we get introduced to or get we uses the Android framework it encourages the component reusability. That is if I want to create application, suppose I want to create application to view a PDF file. Then Android this framework provides me a functionality or two functionality so that other application can also use my application. If there is a requirement to view a PDF file then they also use my application to use in their code. So this is the component reuse. So using that we can publish shares our activity service data with other applications. And also we can create, we can replace or we can enhance existing features in the Android. That is we can replace phone dialer application, email client, etcetera. The main components in this framework are activity manager. So what is activity manager? In Android there is activity which is main building block. So activity manager actually manages the activity life cycle. It also manages the activity stack that we are going to explain in next slide. Window manager and the view system they controls or they manages what is to be shown on the screen. Also there is a notification manager you all have seen Android phone so there is a status bar we can see notification on the status bar. So notification manager manages that. Then there is a telephony manager. Using that telephony manager we can access the underlying telephony stack and telephony hardware using that. Then there is a resource manager. We can use various resources in our application like any drawables or images, XML files. So using resource manager we can manage it. There is a location manager. In location based systems we require GPS and we use locations. So in that case location manager is required. This is the application framework. So now let us understand let us see what are the Android building blocks. If we want to create an Android application we create one or more of this component. That is activities, view, intent, services, notification, content providers. These all components are loosely coupled components and they bound together by using android manifest.xml file. So if we create any Android application there is a manifest file and in manifest file we write or we specify every component that we used in our application. So let us discuss this in detail. The activity. Activity is our application's presentation layer. So what we see in our application is an activity. So we can say that activity has a screen and it processes some or it has to process something and typically it corresponds to one UI screen and in Android only one activity is visible at a time. So what happens to other activities? So there is a concept of activity stack. If you want to create activity we need to write a Java class which extends activity and we get all the callbacks that is on create on resume that we will see later. We can implement using that. Then there is a intent filter. That intent filter specifies the purpose of the activity. That is what this activity is going to perform or what is the function of that activity. Let us take an example. If I want to create a activity which captures a image. So the intent filter will specify an action that it will capture image and it requires a data. The image path that it will store image into is memory card. So any other applications can use that intent and fire the intent so the my activity will get started using the same message processing mechanism. And for creating activity we generally activity is a full screen but we can manage it to like we can use it like a dialogue theme or transparent, semi-transparent. So all this functionality is also provided. This is the activity life cycle. Activity has 4 states. First is active state then there is inactive then stop and pause. Whenever activity is visible and it is focused it is in active state. If suppose another activity comes up and our activity goes to the foreground then it can be a pause state or it will be in a stopped state and if activity is not in an android stack or activity stack then it is in inactive state. If we write activity then we will get all these callbacks. When our activity first get created we get callback to on create method. Here we initialize all the UI components and all the process we all the threads we need to perform that we will initialize here. Then after on create there is a callback of on start. After on start our activity will be a visible in a visible state but we cannot say that it is in active state. It may be in pause state because on start it is visible but it is not focused so user cannot interact with that activity. So when we get a callback of on resume that is the time where our activity is in active state. So we can interact with our activity and the exactly the same process in a reverse direction on pause we will get callback to on pause when other activity comes up or our activity goes to foreground and whenever our activity get destroyed we get callback to on destroy and after on destroy it will be erased from activity stack. In android if we press a back button it will finish the activity. So suppose our application is active and I started activity and I press back button then it will the on destroy will call and it will erase from the activity stack and my foreground activity my activity will comes up. Now the second important building block is service. In creating application we many times comes across a situation where we want to perform a long running applications and long running task and which does not require UI that is download a file or play the music. So what we do if we do in activity so what happen you have activity get paused so download will also be paused. So there is service using that service we can implement all the necessary functions. Service do not have UI so it only used to perform a task in the background and generally long running task. But suppose service have to show some UI that suppose a file is downloading and I want to show through service that I am downloading so what service will do because he does not have the UI. In that case android has provided a notification manager that so that service can notify user through notification manager that something is downloaded. You have seen in android market that it downloads application then there is a progress dialog in the notification that it shows the percentage. So it is through a service using notification manager. Also to start a service there are two forms. We can directly call start service and mentioning the service name it will get start and it will be in a running state until and unless anyone explicitly called stop service or the service itself called stop self until and unless it will be in a running state. And another form is a bound that is if suppose one there is music player service. Suppose there is a music player service which is playing the music in the background now my activity it want to show the UI that 30 percent that is 2 minutes played 3 minutes depending what my activity will do it will bound to that service using bound bind service. So when I say bound to that service it will gives me a handle and that is the eye binder and using that I will access all the service functions and I can again stop it. Now the next important component is a broadcast receiver. Android system broadcast various events like my battery is low or I have one incoming SMS. So these are the notification for users so that user can take action if a battery is low then it notifies user that you should do something to avoid your power to your battery backup. So in that case broadcast receiver is used which actually receives the events and it performs it task. And to use broadcast receiver we need to write a class that extends the broadcast receiver and one more thing that we need to do is we need to register that receiver that it will receive the event by using we can mention it in the android manifest file or in the Java we can register it and there is we provide the intent the same intent which has action which has data using that intent the broadcast receiver comes to know that what actually happened. The next component is content provider in android we can store data we can create data and we can share it across the all applications all the applications and it is possible through a content provider and it is the only way to share the data across all applications. It is just like normal database we create a tables we create all the relational database like columns then there foreign key primary key everything same as that and the database is exposed through a URI it is a uniform indicator uniform resource indicator. And it so that any other application has that URI will access our data which can modify our data and use it the example is a contact manager the contact provider it is a content provider which allows us to get a mobile contacts and we can add new contacts we can edit existing contact so this is a we can create our content provider too. So next component is a intent it is a message passing mechanism what is the message passing mechanism suppose my activity one to download a particular file and there are two other applications which have implemented the same so what I will say I will create an intent object I will write an action that download a file and it will I will say start activity so what will happen the android in the background it searches for the action that how many activities or how many components have resisted to that performs that activity or that perform that action so it will show the user that there are two application that are using the that can perform the action so user can select we have we normally see an android suppose we want to view of image file there are various image viewers available in our phone so it shows two that is our inbuilt gallery or some third party image viewer so they provides us the two options so that we can select it will start so it is by using intent it starts particular activity or service it is a runtime binding the intent object has four primitives that are action data component name and extra I want to view a image file so in that case the action is action view and the data is my files URL so it I will publish the intent and android will searches how many activities or how many application have resisted to action view so it will start and it will give that data to that activity so that this activity will display the file from that data and component name is we can directly start the another activity by giving a component name that is our package name and class name android manifest file every application contains one manifest file it has the information about all the necessary components used in the android and the components are activity service broadcast receiver and content provider and it also specify the intent filters that is we have already seen what operation it is going to perform then manifest file also specifies the permissions our application uses the bluetooth or camera then we need to provide a permissions that I am going to use this permission so in manifest file we write that permissions and also we need to write minimum api layer so that application will not get installed to the devices which has lower api layer then if you are using any third party libraries like google map or something then we need to explain we need to specify this is on manifest file the view is the basic ui building in our application what we see is everything is a view so we see a button we see edit box or any list everything is view view is nothing but a rectangular component it has properties like it has width it has height we can specify manually or we can assign them a value like fill parent or match parent wrap content so it will get automatically assigned value then there is the views can respond to events like if I click on the event or if I long press on any view so I will get a call back so it is a user interactive then there is another concept of view groups it view group is again it is a view but it has some more things to do view groups are used for creating a layout managers in android there are various linear layout relative layout they generally used for various screens to the ui will be consistent if we use a layout manager if we hard code the values then for every device the values will differ and it will get ui so user will not like that so layout manager we use and it is organized as a tree so in view groups we add groups and we specify their alignment and if the views what android has provided that not satisfy our need then we can implement our custom views by extending by writing a class which extends view in our application there are various needs that where we need to store a data so android provides various techniques by using which we can store data like share preferences then file system then SQLite database so let us study all in detail share preferences is nothing but a key value storage a key value pair and for storing it allows various all the primitive types like integer, long, string, boolean we can all store in shared preferences and this shared preferences also get shared across application if we need and if we not it is only limited to your applications so there is a mode when we create our shared preferences we need to specify the mode when we specify a private mode it is just limited to our application and if we specify it is world readable then all application can read it but they cannot modify and if we write world writable then anybody can read anybody can write generally they are used for application specific user settings now the next storage is a file storage in android we can write data to internal memory as well as to the external memory and if we write data to internal memory it is secure that any application cannot access it so if the need of application is to write a secure data that anyone cannot able to modify or read it then we write into an internal memory but internal memory is very low so we need to take care of that and also we can write into cache directory it is also in internal memory so if android is running a low memory then android explicitly delete the cache so that is also we need to take care and we can write into external memory so there is no security nothing constant provided so any application can use read can do anything on the external memory generally we use this for saving like our media files on the external memory it also provides the SQLite database it is just like any other database we create by using by creating the tables by creating its columns we also derive their foreign key primary key and it is accessible by its name and it is but this database is not accessible to any other application so it is just application specific and we can perform all the crude operation that is create read update delete we can fire various queries on that and but in SQLite the data type supported are very less compared to other it just support integer real text and blob if you want to write a boolean we cannot we need to use the integer in that case and there is no long so we can use integer for storing the long values now when we create any application this is the structure actually we get created if I created a hello application then this is the source folder where this is the source folder where all my activities all services will get created then this is the gen folder that is generated where only one class will exist that is r.java that r.java class is a resource that is a resource class there are the id's of resources that we use here are get stored just id it is just a reference to that resource and in there is a resource folder in resource various resources that we use for building android application will reside in animation folder all the XML files that we use to run to perform animation is stored and in color there is a color constant get stored there is a drawable folder where all the images that we use for android to develop a UI get stored and there is a something that is hdpi, ldpi, mdpi android supports various screens so my mobile is 2 inches and this is a 7 inches tablet so how we can we maintain the consistency in our application so android have provided this feature so it is also runtime binding so depend on the mobile density it will select the images from specific folder so we can create a set of images that is small image then medium then high density image and we can place into every directory so that depending on the device size it will select at runtime also there is a layout file we create our UI in XML that is there are all our layout files which resides here and there is a lib folder if we use third party libraries like adjacent or anything then it will reside here we need to give a class path and then if you want to show the menus in our application then there is a menu and raw in the raw folder if you use some audio file or any video files that will not compile it will reside in the raw folder in values string constant will get stored so this is required because if I want to write application for India and so the string constant in any Indian language and suppose now I want to publish that application in Russia so there is now what will I do the string constant that I defined is in Indian language so how is going to take so android has provided that resource so that it is in runtime will detect the local of the device and it will select the resource depending on that so if I create two resource file one is for India one is for Russia then depending on that device it will select which resource file so the user notification or the all text will be consistent across the world and finally this is the android manifest file that we have already seen and default property file is just shows the min api version sdk version so how application get built in android application there are java files there are resources files so java files using java gets converted to dot class files and the resources file get converted by using the apt tool that is the asset packaging tool so it creates the r.java file and resources dot arsc file and then there is a dex tool which converts dot class file to dot dex file and finally that dex there is apk builder tool which gets all the resources all the dex files and compiled resources and it package two into one file that is apk file it is just similar like rar or zip file and finally if you want to put it on the device we need to sign it for a debugging purpose we sign it using a debug key it will get from the sdk but if you want to launch that apk on google play or market we need to sign with our own private key so java key tool provides all the information how we can sign it so after signing our apk is ready to get launched and one more thing that required to get launched on the market is zip align tool it will minimize the usage of memory on the actual device so after all the completion all this process our apk get created and we can put this on device and we can use adb tool or we can directly download from the market to install on device