 There is an introduction about me, apart from that, I'm also the organizer of this group called Bangalore Android, we're about 3000 strong, 500 or more members, biggest Android group outside. If you need one summer, we do all kind of things around Android, have our own media. So if you're interested in Android, just go ahead and join our group. It's on billardware.org, right? We have about 3000. Yeah, that's all the meaning. Just go up and sign over here, you'll get access to the mailing list as well. So let's quickly discuss the Android app building blocks. These are the building blocks of Android. So if you want to develop any kind of application, you need to be aware of this. So let's quickly go over one by one, all of these. The first thing that you should look at is activities. I think I've talked to some of you about activities. So how many of you know what an activity is? Okay, Ashish, go ahead. What activity is this week? Yes. Is this a screen, do you think something happens? Absolutely. Ashish, yeah. From your experience. So, activity is, I think, the first thing when you open an app, there's basically an activity that's launched and I think it's working. So as you can see, this is a Twitter app over here. It's the screen, the whole screen is an activity. So activity is a window where you can draw stuff. And draw stuff means you can have text, you can have images, you can have all kinds of, you know, user interface on top of it. Typically in an application, you have multiple activities. For the Twitter screen, right, when you launch, you have to enter your username and password. So that is one activity. When you enter that, you click on login, that takes you to another activity. So in an application, you'll have the main activity and then you'll have multiple other activities. So the activity is responsible for drawing the user interface on the screen. Any questions? Very simple. If you look at an Android home screen, that is another activity. If you're dialing a phone number, that's another activity. All those are examples of different activities. Intent. So let me give an example for this. So let's say you have a home screen. And let's say you want to dial a number. So let's say you have a home screen and you want to dial a number. So you click on the dialer icon over here, click on the button. What happens is, it launches another activity, which is the dialing home screen. This is another activity. Is that clear? So what happens is the activity one launches an intent, which enables it to go from activity one to activity two. So it enables you to move from different activities, between activity one. Similarly, when you enter the phone number and click on dial, it goes to another dialing screen. What happens is it launches another intent to go to that screen. That's how you can move from one screen to another screen. So if you're building any application today, you have multiple screens, you need multiple intents to move between those screens. You can also pass information between activities using intent. So for example, in this case, when you're moving from activity two to activity three, you're passing the phone number. So activity three basically knows, this is the phone number I'm supposed to dial. So you can pass information between activities using intent. The other thing you have to note is, activities have a life cycle. So let's say, currently activity one is in the front of your screen. It's called a foreground activity. Whenever you launch another activity, the activity that's there before, that goes into the background. Whereas activity two is now in the foreground. So activity one is then paused and stopped. It's put on top of a stack. It's called the activity stack. So only activity two is in the foreground and that is the only activity that's been processed. That's the processing that's going on in that activity. So let's say you're playing music in activity one. As soon as you launch activity two, the music is paused and stopped. You cannot play the music anymore. So you can only do, you should typically do UI stuff, small processing that you don't need to continue when it's paused in the activity. You don't do anything that's long-term in the activity. There's a tab that is in that activity. So it's a pretty different tab that still is in activity one. Good question. So what happens is when you move to a different tab, it goes to a different fragment. These days it's fragments. In the older, this is a very old screen shot. So what happens is this is the same activity. Even if it's a fragment, it's part of the same activity. You're not moving to another activity. It's in the same screen. The lower part is changed. It's the same activity. I'll explain fragments for a little bit. So when you have multiple activities, there's an activity stack. When you press the back button on your Android phone, what happens is the foreground activity is then stopped and then the activity that's on top of the stack that's paused. And that is shown on the screen. Similarly, this is what happens when you are pressing the back button. Some values on activity one. I want to focus on operation of the values on activity three. Okay. Okay. So the question is if you have activity one and you want to pass something to activity three. If you want to pass something, if you literally want to pass something, you can pass a sequence. That's the best way. You pass an intent to activity two. Are you going via activity two or are you going directly from one to three? I do. So pass it to two. Two will pass it to three. Okay. If you don't want to pass stuff, there are places where you can store information that's common to the whole application. You can use that. You can use databases. You can use a lot of different things. But if you want to pass stuff, I would say pass it to two. Two will pass it to three. Okay. Any questions on intents? So intents is not only from activity to activity. It's also from activity to other building blocks. You come across services very soon. So activity, if you want to launch a service, again, you'll use an intent. Okay. One question. So you can also use intents for cross-app communication, obviously. Yes. Sometimes there is a... So we say apps gets confused about which app you're in. Like in Chrome, you open, say, share a link via Gmail. Correct. Now, suddenly, Gmail has become part of the Chrome. It doesn't launch a separate app. Correct. So you're just wondering why that happens. So that's the way it's designed, I guess. Sometimes you want to separate it. Right. Correct. So what happens is, when you do a share a bio intent, that's part of the same activity staff for that application. So it's not completely a disillusioned application. That's, I guess, the way it's designed. So let's look at the next building block, which is views. So till now, we discussed the whole screen or how to move from screen to screen. Views are individual building blocks of... Like individual UI building blocks. So they are described in XML typically. So what happens is, in case you have a team with designers, so the coder can focus on the code and the designer can design the UI separately in an XML file. This conforms to the MVC architecture. So you have your code, you have your UI, and you have your data. All three are separate. So the UI is typically made in XML and you can have all kinds of events. You can click on buttons, you can long press it, you can drag it, and so on. All these events can happen on a view. So let me give you an example. So this is a prototype application. The top part is called the action bar. So this is an image view. This is another image view, this is another image view, and this is another image view. So all those are individual views. Then there are various types of views. There are image views, there are text views. There are buttons. There are edit text where you can enter data. All those are different types of views. If you see the row below, this is an image view. This is a text view. So all these are different views. And you can combine all these views together in something called a view group or a layout. How they are arranged together is a layout. So you can specify that the image on the left, image has to be on the left hand side. On the right of that you'll have a text view. Below that you'll have the text view. The arrangement of all those views is called a layout or a view group. We just call it a layout for now. So in your application you'll be writing a lot of layouts. So basically all these individual views will make one layout for this row. These rows combine and make a bigger layout. And so the whole UI of any activity or any screen is basically a big layout. So if you make an activity, you have to make the UI for that activity. Basically what you're making is the layout for that. Any questions? So what happens is when you have a layout or any view, there are some parts which are derivative to it which you eventually pass some data from the controller and then it gets built up. So does it happen a similar way over here? Also can I create a layout with placeholder content which I can populate? Absolutely, absolutely. It's the same way. So you can dynamically edit stuff, update stuff, fill in data, all kinds of stuff. It's the same way. The way it happens, the way you declare is a little different because you have the code part separate, you have the XML separate. So you can create a view and code and then inject it. You can do all of that stuff. But it's the same concept. So when it's a view with an XML, there are no placeholders there, right? So what you can say is an empty layout. Then you can get the reference to the layout and code and say add this view in runtime. You can get the placeholder. You can fill anything inside it. So you can put placeholders there? Absolutely. You can completely make layouts, add layouts, remove layouts, everything that happens with you. So these are views. Any questions? So you can have long press, you can have press, you can have drag and action. You can do all kinds of stuff with it. Yeah, sitting there. So in this case, the thing is update and edit the way you want to add a few path views. Your part, which is at the bottom, will this part be part called a view or it will be called your layout? It will be a view group. A group of views, basically. Together, so this view group is probably a relative layout. So this is a relative layout. The arrangement of all the views is called a relative layout. So in the relative layout, what happens is you can tell how each view is arranged with respect to another view. So what happens is this whole thing is called the parent, the whole program. So the image is on the top left of the parent. This text view is on the right of this image view and it's at the top of the parent. So you can define each view with respect to the other view. The whole arrangement is called a relative layout or a view group. So don't worry about relative layout right now. But basically you can arrange all of those individual views too. So I'll probably show you a simple view of the layout. Okay, next is content provider. So content provider is a little advanced concept in Android. So let me illustrate this with an example. So let's say you build an application which is a contacts application. You'll have different activities. You'll have multiple activities in the application. Maybe one activity to add phone numbers, one to display the list of contacts, one to edit all kinds of different activities. So where will you store the data? Like the name, phone number, email address. Where do you think you should store the data? In a data. Typically it's stored in a database. Instead of storing it directly in a database, in Android you use something called a content provider. So content provider is basically a wrapper on top of a database. You make it in such a way that other applications can also share that same data. So what happens is instead of directly storing in a database, you build a content provider and you store the logic of where to store the information in the content provider. So the content provider will know, okay, this data I want to store in the database. This data I want to store in a file. Maybe this data I want to store in the cloud. That logic of where to store the data, how to store it is in the content provider. Again, it's a part of your application. You have to write the code for that. But that runs on the system level. It's not only in the application level, but on the system level. I'll give an example of that. So what happens is, let's say activity 1.1 is for creating a new contact. You're creating, let's say, a friend's phone number. You will ask the content provider to store this information. The content provider has the logic of where it should be stored. It goes to the SQL line database, which is the database on Android, and stores it over there. You have programmed it in such a way. You might want to store it in a file. It depends on which side. Then it's stored. If you have another application, this is where content providers are really useful. If you have another application, which is an SMS application. Now, traditionally in databases, if you have one application, everything is sandboxed there. Like the database is also sandboxed. Very difficult to access the database of another application. So content providers is designed to specifically solve that problem. So if you have application 2, which is, let's say, an SMS application, you need to find the phone number for a person. The phone number will be stored by which guy? The contacts application. It's not your application. You are building the SMS application. So you need access to the phone number. So what you do is you basically ask the content provider of the contacts application. Where is my phone number? Where is the phone number for this person? The content provider will have the logic of knowing where the data is stored. It will go and look at the DB or whatever. It will get the information and give it power to the activity in your application. So similarly, if you are building in your own application, you can either just build a database. If you don't have a really complex app, build a database, don't worry about it. But if you want other applications, even other applications from your products, if you have a free version, if you have a pro version, if you want to share data with you, you can build a content provider. So that data sharing is completely simple. So basically, when I create an app and I create a content provider, I need to basically document content provider for other app players to be able to understand how to get the data from my app. Correct. If you want it. You can make it in such a way that only your app has access to it. So there are many users of content provider. The biggest one is what you said. The other things are like loading easily. So there is something called loaders. So whenever you create a list view, but you have a different, like in Twitter, all the tweets are being loaded. So there is something called loaders which makes loading very easy. It's an Android component. So loaders require a content provider. It's built in that way. So if you just build a data piece, you cannot use that. You have to build your own loading. So it's a recommended practice to use content provider. Any questions? So if you have other applications, right, if you build another application which uses the content, then you can, again, that application can also vary the content. You can specify which applications can access the data, how they can access it. You can define the security parameters and all these things. And you might want to expose some data, like maybe game, phone number, you might want to expose. Maybe email ID is something you don't want to expose. You can define all. Any questions? Next, we look at services. So as I said, right, the activities are started. They are created, they are started. And when another activity comes in the foreground, that is paused. You cannot play music in an activity. As soon as another activity comes or a call comes in, that activity comes in the foreground and the music is paused. So that's why you cannot do background tasks in an activity. For that, you need something called services. They have faced their tasks that are in the background. So if you're building a music player, typically the code for playing the music would be the service. And the code for interacting with the GUI, the button press, that would be an activity. So the activity would interact with the service and get the information. The service would update the activity. Any questions? Next, notifications. You've seen Android notifications. It's very simple to create a notification. Two or three lines of code. You have visible alerts. You can have icons. You can have expandable notifications, vibration, LED notification, all different kinds of notifications. Very simple to create. You have to use something called the notifications manager to create notifications. Finally, Android manifest.xml. So how many of you kind of looked at the manifest file? So manifest is it's like a catalog of all the functionality which versions of Android you should support. What are the different libraries you're using? The package name of your application. All the permissions that you might be using. Permissions are very important because let's say your application wants to interact with the internet. You're gathering some data. So for any Android application, if you want to access the special features, you need permission. So when the user downloads the application, you see the permission. So you know before installing what are the instructions. That's why you have to mention the permission. If you don't mention the permission in the manifest file, even if you download the application, install it, you've forgotten to use internet permission. It'll not work. So if you take the permission, it will be denied. Any questions? So we've walked through the development environment. Eclipse is the older development environment for Android. So how many of you are familiar with Eclipse? How many of you are familiar with Eclipse? So quickly you've walked through it. So the whole thing is called perspective. The different windows, like the edit areas, views, all these are different areas of perspective. So give you an example on the left. On the center is where your source code will be there. Source code, UI elements, all that in the center. Left is the package structure. It's kind of important. The bottom will get all your error messages, laws, and so on. So the right side will see all your program elements, outline of the variables using the method, and so on. So the UI is a simple drag and drop. Drag from the left side and put in the center. You also have the functionality of an emulator. So create a new emulator. So what happens is in case you don't have an Android device, you can create an emulator for any version of Android, and then it's like a virtual device where you can test your program. Emulators are very useful because maybe you have one or two devices. You might not have a tablet or a very high resolution device. You can create all different kinds of emulators within the development environment. So trans the actual version of Android and you have the screen, you have the actual buttons, then your emulator is really powerful and you can give it GPS coordinates as well and you can move it around and solve it. Pretty powerful. So let's not cover how to install the SDK. Let me quickly launch Eclipse and show you any questions. So what would you like me to cover? Like a simple program? I have small question with respect to this emulator. For example, I'm creating a small contact tab. There is already an existing application for the contacts. Will there be any existing contacts available? Yeah, it's a good question. So there's an existing contacts application which comes by default. Open source Android application. So that's chosen content provider which you can access. So like I showed you, you can create a content provider. Android has already created the content provider for you. So in case you want to retrieve a contact you can do that using the same content provider. So I think there's a contact content provider. There are all kinds of different content providers which are there. So there are some existing data. Can you delete those data? My functionality intends to delete existing contacts. Is that possible? I think so. It depends on the permissions. I'm not sure if you can delete it. Yeah, we have to look it up. But it should be possible. So when I start a new project and then I make a new layout so how do you make an activity to and then link each other? So that's a common question I think. So I'll just show you how to do that. So when you install Eclipse there are a couple of development environments for Android. One is Eclipse. The other one is called Android Studio. It's based on IntelliJ. Eclipse is still the better platform. I mean not the better platform. It's the more better platform and it supports more features as of now. So the newer one is better in more senses. It's faster and got lots of really cool features. But for now Eclipse is really good. We'll start and create a new Android project but we can't see this. Basically we have to do a file set. This dialog will come up when you click on new project. Enter your application name, project name and so on. Just call it Hack Night. Keep all the other values as default. Select the minimum SDK version. So we're not changing any of the minimum version of Android. And the package name is important. How important is that? Package name is kind of important because many people might have the same application. So it's important to have a unique package name. For example, you are building a contacts application. I would change the second parameter. I would call it let's say I want to do an RPG. So I would call it Commodore RPG. Is this like a companion? It's not something that's specific. It's based on users. Some people call it Commodore Android or something else. How do you know that it's something that I'm putting there? Basically, yeah. So try to make it unique and you cannot do that. You have to guess. So typically Comm.organization name or something shouldn't be occupied. You can check the market. So if you go to the Android market So if you see if you go to any place to a link so the link will be there at the end will be the package name. So you can go and check it out if your application is in front of you. So let's say you go to apps and just do some other app. So you can see Comm.dexshara.is So I just can't get the place the package name that I want. I can just check it. So right now we just keep everything to a default view. So here you can change the launcher icon and stuff. You can change it to some clear part. Something like this with the color and stuff. You just leave everything to a default value. It's kind of important because it tells that I'm creating an activity for it. What is the name of the activity? So it's creating your home screen. You want to change the name, you can do that. It also creates a layout file. So what do you think is a layout file? Excellent. So what does it do? It's a UI file. UI file? Yes. Correct. So it's creating the activity. It's creating a corresponding layout file. Click on finish. So the other thing. So it's created this. Created this application. It's created the layout file very simple. It's got a Hello World text. So what a very big program structure. So before that I'll choose something which is kind of cool. It's called DDMS. So this is a Java perspective. There's another perspective called DDMS. You can add that. What that does is basically track any emulator or virtual device or real device that you might want to create. Let me show you an example. So let me create a virtual device. I have many virtual devices. I'll launch a virtual device. I have many virtual devices. Let me start a virtual device. So this is the emulator. It's going to take some time to start up. Till that time let's look at something else. So this is the button to create existing emulators. On the top left. My Android Virtual Device Manager. Over here you can go and create different emulators. You can have a 7-inch device. You can have a 5-inch device. There are pre-existing configuration for all Google devices. Nexus 7, Galaxy Nexus Nexus 4, all that stuff. You can create any resolution any kind of difference over here. Let's look at a program folder structure. There's a source folder. Any guesses what that could contain. Any kind of code. Any source that you want. It will be divided. It will have the package name and all the code will be divided on the server. So it will have the main activity code. So we'll have a look at that soon. So it also has different folders. It has a gen folder which I'll come back to later. It has a resources folder which is important. You can see that the UI this is called activity underscore main.xml This is the xml file that represents the layout. It's in this folder called layout folder. That folder is inside the resources folder. So resources has all your resources that might need images. You can say this is an image. So it has different image folders. So there's drawable dash htpi, there's mtpi, xhdpi and so forth. So all these are different basically resolutions. So different screen densities. So most of the recent phones are very high resolution phones. So those form under xxhdpi. You see the Galaxy Galaxy S4 Galaxy C1. Those are xxhdpi. They have pixel density of more than 320 adults per inch. So why you need so many folders is because let me show you. So an image in different resolutions. The same image might have different sizes for different resolutions. So what happens is you don't have to really manage this. So Android does this for you. Typically in the you just put an image in the highest resolution folder and it automatically speeds it down for you. But I would still recommend there are many tools like you go online. Even there's an Asset Studio it automatically does it for the resolutions. So you can see the same image right? This icon will look the same size on a very high resolution phone. It will occupy the same screen size. But you need a very high resolution image to look like that. That's why you have different folders. And the name of the file is same. So Android knows what is the resolution or the density of the phone. It will automatically go to that folder and select that image. You don't have to do that. It will do it anyway. That's a drawable folder for all the images. Any image that you have will be stored over here. There is a Layout folder where you store the layout, the actual UI, how it looks and so on. This is activity underscore .xml file. When you double click on that this is how it looks. You can have so this is the graphical layout. There's also something called the XML layout. This is how the actual XML is. You have a relative layout on the top. And inside that you have the XP. So all your layouts will be there over here. There are other different things like values and menu folders which we can cover. The Android Manifest file, we discussed that where you mention all the package names and permissions and so on. That's over here. It's an XML file. You can see that it's the name of the package, the version number, the minimum version of Android supported. You also have to mention all your activities over here. In case you add a new activity, I have to mention that over here. Other important thing is the general folder. So what happens is anytime you create any new resource, it might be an image, it might be a any kind of resource, it might be a button also. When you do that, Android automatically updates this file called r.java. It catalogs that resource. You add a new button. Android says, I want to catalog it that you can access it very easily. Because other than the resources folder, normally you would have to import it or do something else. Android makes it much simpler. You just add the new resource and it will generate an ID for that. So, are you an example? Basically, you would come here to get here again. You don't have to come here. I'll show you how to do it. So, for example, this is a class r. ID is called this is ID. Currently, there is just one ID over there. What I'll do is I'll add a new button to this layout. I'll add the button. I'll just quickly drag and drop a button. If you go to the XML, you can see the ID of the button is button one. All you've done is added the button. If you go to the ID, you can see that the button one automatically has been added. So, you don't have to do anything. Anytime you add a new resource, it will be added. How is that useful? You can do that. You don't have to add. So, this file is always auto-generated. You don't have to do anything. Whenever you add something, it will come over here automatically. You shouldn't change this file. You can change it. So, how is this useful? Let's go to the source of our program, which is the main activity. You can see that onCreate is a method which is called when the activity is created automatically. So, typically any UI initialization that you want to do, you can do it a bit. So, what do we do here? We call this Metricorps. We call it Metricorps. We call it Metricorps. What do we do here? We call this Metricorps setContentView. You set the view of your application. So, you set the view to your layout file. The layout file is again a resource. The name of the file is activity. So, let me show you that. It's r.layout.activity. That's a resource. So, Android automatically catalogs it under r.layout.activity. So, instead of importing it and making it complicated, whenever you want to access a resource, you can just say like the button to you will get it directly like this. The reference to the file. Any questions? So, let's go to dvms. So, dvms is kind of a perspective where you can see what's happening in the device. So, we launch the emulator. The emulator is kind of ready whenever. So, this is the emulator. So, you can see that this is the emulator. And this emulator shows up in the dvms. You can see all the running processes. All different processes are running. And you can see a log of what's happening. It's a log of all the error messages, debug messages, all kind of stuff. You can see the file explorer. You can see the folder structure and so on of the device. You can do a lot of cool things like if you want to send, you can send a phone call to the device. If you're testing some scenario, you can say call the device. It will send a virtual call to your device. Pick up the call and so on. Right? So, you can send calls, you can send sms's, send location details. You can check out let's say what are the threading parameters for this particular process, how long the thread is going to be, all kinds of detailed information about the device. In case you're interested in what's happening on the device, the log of anything, DDMS is what you have to get to. It's not there by default, but just pick or add and get it. Back to Java, let's run the program. What we do is right click on the name of the program, run as, and not after the name. So, any questions to allow? No. So, just before that you can see the program we had edited. Auto Java again, whenever you add any new resource, it can be any kind of resource, Android automatically catalogs it over there. And then you can use it in your code. You can use it to reference that same resource in your code. So, I'll give you an example. Let's say somebody said that we want to check your launch in your activity. Let's quickly do that. What happens is when this button is clicked, let's launch in your activity. First, let's create the activity. Activity should be created in a separate file, a separate class. Right click, new, class. We'll call it my activity. Superclass, it should extend activity. Search for activity. Click finish. Generate the class for you. Activity. What should an activity also have? On create. So, you can't see this, but basically there's this folder called, on the top there's a bar called source. On that you click on override. So, what this does is gives you the ability to override any of the superclass methods. So, these are the activity methods that you can override. It will be over here. Shortcut is, there's no shortcut by default and you can't see it. With source, on the top, override implement methods. File, edit, run, source. So, you can override other methods also. I was talking about activity can be paused. So, I'm sure there's a restart, resume, restart, start. Lots of different methods you can override. You can see what's happening. So, let's go back to main activity. So, this is called my activity. You have to, So, these are superclass methods. I can just override them. So, it's an actual activity. So, if you want to do any functionality when the activity starts, stops, resumes, whatever you can do. So, on create, what happens in on create? In the other activity that you've seen. You have to expand the layout basically. If you go to this, you write this line. Set content view, r.layout.activity. Basically saying that the layout of the activity should be whatever is there in r.layout.activity. Okay. Let's create a quick layout. I click new, Android XML file. Okay. There are many layouts to choose from. I'll just quickly choose a relative layout. We'll call it my activity layout to something. I mean, you can call it one-to-one. It'll be created in the layout folder. Go to the graphical view. Drag and drop something. Let's say you drag and drop another button. Okay. We'll put it over here. Save it. And you can change the text also. Let's change the text to... So, this is the XML tag, right? The element for the button. So, there is a particular like, Android text. Whatever you want the text to say, you can change it over here. Go back to the graphical view. You can see that's changed. So, now this is the layout file. Inactivity. What should I write over here? In my activity. So, that's the layout becomes the new layout. You want me to... What should we write? What is the method? I don't remember. It's in the other activity. Set content view. Set content view. What should we do? R.layout. R.layout. My activity there. Okay. Simple. Save it. What else need to be done for this activity to be recognized? Manifest file. Any activity, any building has to be mentioned there. Could be a manifest file. Okay. I like to do it in code. Let me show you how to do it visually. Let me show you how to do it visually. So, you need an activity tag. The name of the activity tag should be my activity. It should be my activity. Okay. Simple thing if you define is basically what is the complete package name? The fully qualified name for the activity. Okay. com.activity. I think it's the right word. Okay. Simple. Any questions? How can we link this activity I've not linked it. Two separate activities. The second activity is not even being called. Okay. We'll just define it next. Okay. Now we have to launch the second activity, right? But the button is clicked. How do you get a reference to that button? This is where that r.id is useful. So, let's quickly do that. Let's create a button. Button will call it button2. Okay. Again, you might get such errors, right? Many ways to resolve it, like hover over it. We'll tell you how to quick fix it. So, it's basically saying that this button is the button is not important. Just click on important and we'll get fixed. What we'll do is now, we'll have to do that. So, what have I done over here? I've created a blank button. Just a container. Is equal to... I'm finding the view. So, this is method called find view by id. If you pass the id of the button, which is what r.id.button2 you can call it whatever you want. You can change the id as well. r.id.button2. If you give the id, it will return the view. Now, button is of type view. The super class, like the base class is view. So, any view you can get from this. It's going to return something of type view. If you want to type, class is a type button. If you want the button function. So, you might have some text view. You might have edit text. You might have any kind of view, even view groups in your layout. If you want a reference to that, let's say if you have this a placeholder type, dynamically you want to add a button to the placeholder. So, you get the reference to the placeholder and then you can add stuff to it. Any questions? Okay. Next, we'll create a listener. Set onClickListener. So, what happens is you can attach a listener like any Java program. Attach a listener to the button. So, whenever the button is clicked, it will be basically this listener will be in. So, what I'm going to do is I'm going to write it from scratch again. As I said, onClickListener. Inside the listener, we can dynamically create it like an anonymous inner class. Okay. Again, you'll get some errors purely if not imported to listener. Just import the listener and all the errors will be gone. So, what I'm doing is I'm setting an onClickListener and the listener like defining in real time. Okay. I'm defining it inside the bracket inside. Okay. And if you want to do something when the button is clicked, you have to define it over here. Okay. Anything you define over here will be called when the button is clicked. The name is onClickListener and this is onClickListener. Okay. So, this is the same as doing something else. This is anonymous inner class. Okay. This is the class. This is defining the class over there. Okay. It's the same thing I'm overriding the method of that. Let me do one thing. Let me show a message, like a short message. The method for that is toast. Okay. Okay. So, this is method called toast. What you do is it takes some parameters versus the context. Okay. It's basically where you are launching the message. I'm saying moving to activity 2. The length of the message. So, there's a constant defined for a short duration. And the last method is for creating the toast. That show will basically show the toast. Okay. We quickly run this program. So, you have a hello world. You click on button. Okay. We'll show a small text, a small toast, saying moving to activity 2. It's not moving there. You've not written any code for that. Any questions? Okay. Now, what we'll do is we'll what do we need to do to go to another activity? Intent. Intent. Remember, intent to move from activity to activity. We'll create a new intent. Okay. The first is where you're moving from. Okay. The second is the second activities class. Might get some error on the second for reporting stuff. The shortcut command shift to on the map will import everything. Okay. The first one, you might just want to use this. So, moving from main activity to the second activity. Okay. This is just the intent. It's not actually doing anything with the intent. So, what you want to do is not activity. So, use that intent to start another activity. Also, we'll show you how simple errors can happen and where you'll get what and when you're getting the error. So, let's go back to our program. Okay. Click the button. See the error. So, this is what I want to show you the error where you can get the error. So, any idea where you get the error? We had shown you in DDMS the log of all the errors. So, this is very important. I wanted to show you. This is an explicit activity class. My activity. Have you defined it? Have you declared this activity? I'm not sure. Apparently, I have not defined that much. Okay. Let's go back and check. So, if you get some very simple spelling mistakes, it will not fix it for you. So, okay. The cool thing is, if you go to DDMS you find the line number at which you get the problem. You might get a detailed explanation like this. You might not. In case you encounter such a problem, this Google the error. Google from this place. And you would get many stack-off answers on any kind of error. You also get a line number. See, you get a line number. MainActivity.java 27. So, if you go to MainActivity.java and turn on line numbers. See, 27 is the start activity. Okay. Over here, it tries to basically find that activity as well. So, it goes into the second activity. So, again, this is the layout for the second activity. It's completely different from the first one. What was the error? The error was that we did the spelling mistakes. So, we had not spelled the activity name properly in the manifest file. So, it's not able to find that. Okay. Okay. So, that would be a part of the UI. What kind of... So, moving from one activity to one activity, the interaction would be better. Okay. Okay, different animation. Animation is an animation framework. So, there are various animations you can pump it up and so on. So, couple of lines of code you have to write that animation. Animation will go in when this activity starts. It will go in the first one. How do you want to make that disappear? And this one, the appearance will be in a... You can define the XML also, like the animation that you want to have. And animations inside of the activity would just coincide that. Yeah. Any... Sure. So, any view that you have, right? So, you have this called start animation, right? If you define the animation, you can just do on any view or any kind of element you can do. So, any questions? And the notifications as a whole is a particular application. So, that would remain actually... So, whenever you want to show the notification, let's say you want to show the notification when the button is clicked, right? So, you would probably write it except for this... After the stores, you might want to show a notification. So, two or three lines of code you have to get a reference to something called notification manager and then using that, you can notify. Right? So, two lines of code and you get shown a notification. Let's say that the first notification is not an activity thing. Okay. So, more of an application thing. Sure. So, that is triggered from the service. Okay. So, the service is running in the background. Let's say you're in a music playboy and you want the music controls to be the notification center. So, that is powered by the service. So, service runs in the background. So, like you would have the activity over here, like public class, mean activity extends active. That would extend service. There are lots of other methods that you have to overwrite, like how the service is bound and so on. So, but then you have the ability to have notifications from there as well. So, you can power it from there. You can switch it off. Okay. Fragments, right? So, how can I show you a quick example? So, we'll create a new project. Close this project for now. In case you want to get back to your accent, you're free to improve. So, we'll call this test. I'll just move it to a higher version of Android because some of the features we're going to try is a little higher. So, what we're going to do is have navigation now. This is how it's going to work. We'll quickly make this. So, this has a couple of swipes. So, if you swipe, it'll go to another screen. So, that screen is no longer an activity. So, as I said, the whole thing is basically a screen. The whole thing is an activity. But in this case, when you swipe, it's not the whole screen that's changing. So, this is when you move, the screen is not changing. This part of the activity is changing. So, this part is a fragment. You can have smaller fragments. You can have bigger fragments. You can replace one fragment with the other in this case. So, show you the code real quick. So, it generates a lot of code for you already. So, in the second video, this is a mean activity extends fragment activity because it supports like fragment related features. So, it extends fragment activity. It's still an activity. Inside that, in set content view, it sets it to again activity underscore main. If you go inside activity underscore main, you'll see that it's got something called view pager. So, view pager is an element which can have multiple fragments. You swipe from page to page. It will go from one page to the other page. It's got a title strip. That's the top part that you see, the name of the page. That's the title strip. And there is no definition of the pages itself. The page that you see inside that's not defined. That's defined separately. So, if you go back to the activity, you can see that this is the fragment and it's got its own view. That view is basically fragment underscore main underscore dummy. So, you see this text view over here. It's like one text view with a number. So, that is basically this fragment's X view. So, each fragment has its own layout. So, what this view pager is doing is it's creating multiple dummy fragments and for each of those dummy fragments, it's when you're swiping, you're swiping and swiping. So, fragment is meant for tablets and other big screens, right? It's kind of associated with that because what happens is normally in this case, right, you just have one complete activity. You click on something, you go to another activity. The whole screen is redrawn. If you don't want the whole screen to be redrawn, you can have a particular section which is like a fragment. If you have a tablet type, it's a bigger screen. So, every time redrawing the whole screen doesn't make a lot of sense, right? So, what you do is instead of redrawing the whole screen, you draw part of the screen. So, that's part of the screen. That's why people associate fragments with tablets. So, what happens is, for example, in a Twitter application, you might have two views, right? On the left hand, it's in landscape mode. You might have the list of features, people on the left hand side, the list of mails and the mail itself on the right hand side. When you switch it to portrait, only the detail of the mail will come. Right? So, in the landscape mode, the mail itself is part of the right fragment. The left is the list of mails. When you switch, instead of showing both the fragments, you just show the detail. Like the other fragments. The other fragments you just show. And so, there's a sense. So, right portrait would be important. Is it for the portrait? So, we are not defining the portrait, it's a kind of functionality. This is a very simple fragment where we are seeing that this page has this fragment. So, how do you work with the user to understand the device? The whole screen will be like the same. It will occupy the whole screen. But if you want a different thing to happen. Correct. So, if you want something different to happen, then you have to define a different layout, basically. If you say that when it's portrait, don't show this layout, show some other layout. So, it can get more complex. So, we have intent there is it's shifting from portrait to concept mode. It's not intent. So, those are again different broadcast messages. So, activity will automatically handle these changes. These are called orientation changes. When you move the accelerometer, it will automatically note that it's going from portrait to landscape or whatever. And activity will automatically redraw itself. For any font, you don't have to write any code. It will handle it. But if you want a different design for portrait and landscape, for most tablet apps, in that case, it's highly recommended that you handle it yourself and kind of show a different thing. So, our EDMS, mostly we've covered everything. Any questions? Values. What is that? Values contain something called strings and arrays and stuff. So, we can start here. So, can I change this type? I've got some ideas to represent your normal CSS. Values has many things. It has dimensions, strings and size. So, dimensions for dimensions. So, again, you can have different values folders. You can see there are three different values folder. Four, five different values folder. 11, 14, S, W, 600, ET, S, U, 7, 9. So, these are different folders for different purposes. Drawable has different folders. So, these are called qualifiers. You can have different qualifiers for values. What this means is dimensions. So, you might want some amount of padding. If you want the text to be somewhere on the left-hand side, but you want to give it a padding. The padding is changed on the device. On tablet, you might want more padding. So, you can have dimensions. You can store the padding for different dimensions, like different devices. You can have different dimensions. So, you can accept a 600dp smaller width, 600dp. This is called XS7. This thing identifies as an XS7 and higher. So, if it's an XS7, don't take the dimensions on the default value. Take the dimensions from the dimension files in that folder. So, you might, like, if you go with that folder and select it. So, you margin a 16dp, like, 16 elements on this device, on some other device you might want. Similarly, styles. Stiles are just like CSS. You can have different themes. You can have format customizations and colors and all that. Any style you want to give to a particular one or text, whatever you want to do. You can define this in XS7. Completely different from the code inside and you can define it over the and quickly strings. Any idea why strings could be used for this? Why would you store strings separately in values? Static values? Yeah. Static values? Yeah. Why would you store everything? So, probably multiple values are important. Correct, correct, correct. So, what can happen is yeah. So, if you have values for multiple values you can have, let's say, a string name. What would happen is you would have the same string name like the string name would still be underscore name. But let's say the app's name is hello, right? In French it would mean it would be hello, it would be something else. So, you create the same string name and the value inside of that you put it in the other language, right? In support, in fashion, in localization, you can have different values for different strings. Yes, as well. Different languages, different areas, different screen sizes. V11, V14 is for different Android versions. So, you might want different dimensions because the UI changes so much you might want different strings. I think the layout I have the button. I can change the button color there. But what can I do? So, what is this? It's basically to the back here. It's just like HTML, right? You can put the style inside the element itself or you can separate it here. I can do this from back here. Yes. It's the same thing. So, here's the button, the background. Let's see. If you want to change the background, you can change it to you can make it you can change it and change the color to red, right? And you can change it again for code as well. If you go to code, you can reference the button. You can change the background color from here. And you can do it from styles as well. And then what you do is if I include which one will be the one that gets done. So, if you do the styles and the ones in the button that get applied right away, the code gets excluded. But that I mean that so your layout is expanded over here. If you do the code one after that set the color. That's getting called. Because all the styles, everything is getting activated over here. But still which one gets executed which other two? This is the first one that can get executed. This is the first line to be executed. So, your styles plus the other stuff would get executed here. But if you have a button button two dot set color after that so that will be the last one. What's the best practice? Practice styles. The styles over here you can use the styles is equal to styles. Are there any better UI libraries already created? There are lots of UI libraries. Like there's something called Action Bar Sholok. UI functionality library. So, stop stop bar that you see. This is this bar. It's almost black. This is called the Action Bar. It's not there on older devices. Lots of UI libraries. But there's a site called Android Views. You want to see some third-party views? Which are better than non-viewed views. So, you can see this. They have all kinds of different views. So, there's a progress fragment, page type, message bar, graph library. You can use this graph library. Any questions? Cool. In case you have any questions, just reach out to back. We will draw it. We will draw it. Can you tell me more about the fragment thing? Fragment thing? So, in this example, this whole screen is an activity. You don't want to change. Every time you swipe the screen, you don't want to draw the whole thing again. You don't want to see that you want to redraw it. So, fragment is a very efficient way of just assigning the whole functionality with this part. You assign it a separate life cycle. So, this part is a fragment. When you click on something else, you swipe it. Basically, another fragment. It might have multiple fragments. Can you show the code? You always do that when you swipe it. It must be killed. The swiping functionality is handled when you call viewPager. You don't have to worry about that. But did you import this file viewPager? Yes. It all created it by default when you click next in the wizard, it automatically did all that. So, this is viewPager. It has some adapters, some stuff. Basically, what's happening is every time you swipe, it creates a dummy section fragment and dummy section fragment over there, no one creates you. It's going to create the view that you need. How did you create it? It's in the wizard. File new and add application project. You give it some name. Next one. You have navigation type. You just do so. And you create it. Okay. Thank you. I just want to start coding also. See what happens. So, right now, So, right now, So, So, Maybe I can talk about that more. So, I was born. So, I graduated in 2011. So, I'm also kind of not a UI designer. But it's getting started. So, I designed my classrooms. Oh. Yeah. Okay.