 Hello, everyone. So in this video, we are going to see activity life cycle. I'm Mr. D. P. Gunmal, working as an assistant professor in Valchin Institute of Technology, in Computer Science and Department. So let's see what is activity life cycle. So activity life cycle is an important part in android application. So whenever android applications are created, it has to follow activity life cycle. All it has having various phases into it. So first of all we'll see what students will be able to gain after watching this video. At the end of the session, students will be able to identify different states in activity life cycle and they are going to demonstrate, they will be able to demonstrate the working of activity life cycle. So they can identify and they can demonstrate the activity life cycle. It is possible with help of a simple program. So understanding the activity life cycle. So user can navigate through various states. Whenever an application gets launched, that application will not get loaded immediately as to follow certain callbacks and calling methods. So that callback will move, jump that application from one state to another state. That jumping from one state to another state is done or is achieved with help of callback methods. So what are different types of states that are there in activity life cycle? Like creating is there, stopping is there, destroying is there, pause is there, resume is there. Likewise many states are there. We will see in detail what are the different states in activity life cycle. So this slide just gives you an introduction about how activity life cycle will work and what are different methods inside activity life cycle. Now if I take an example, let's take an example of streaming video player. We have seen there are many players available on Google Play Store streaming video player. If I launch a streaming video player, what actions can we do in that particular application? Generally we can watch the video, we can pause the video, we can resume the video. So this is possible. This pausing, resuming or terminating a video is possible because of life cycle. It has to go with help of some life cycle, various methods because of which this stopping, pausing or resuming is possible. So when a user returns, you can reconnect it to the network. So sometimes network gets disconnected. So when your network gets disconnected and after reconnecting with the network, whatever video you have watched, it will not again start from the beginning. Resume from that particular set. This is possible only because of that life cycle protocol. Now this is an activity life cycle diagram, very, very important diagram, required for every beginner to understand the life cycle. So once you understand this life cycle, you can create the applications based on this life cycle. So first of all, when I open any application, let's say a Gmail application I have opened and I click on that Gmail icon. What will happen when I click on Gmail icon? Application gets launched. So this is the state application gets launched when I click on a Gmail button. Immediately the inbox is not visible. It will take some time to loading time. So that loading time and connection establishment with your messages is done during onCreate. OnCreate is going to work as a connection between your Gmail account, connecting with your Gmail account, fetching your messages. This all things are done in onCreate. Once onCreate is done, your mailbox is ready. It will go to onStart. So the application is now ready to start. Then once application is in onStart, it will go to onResume. Now I'll tell you why this onResume is required. Additional state. In first, at the end, whenever you're clicking on application, you can skip this onResume. I'll tell you when this onResume is required. After this, it will go to activity running state. So Gmail is now visible to you. You can check your inbox. You can compose a mail. You can check your send messages. You can draft a mail. So this all things are nothing but activity running. You're opening a Gmail and working with Gmail application that is nothing but activity running state. Then why this onPause? When this onPause will be called, let's say you have got a call. Important call. So call is nothing but when you get a call, the application will be paused. That is onPause. When you get a call that is given a year priority. You can attend the call. Once you disconnect the call, once you're done with your call, again it will go to onResume. So this onResume will work in such scenarios when you have taken some time and you will come back to onResume and activity again will run. For example, you have drafted a partial mail. You have composed a partial mail and suddenly a call comes to you. Will that mail be raised? No. So it will be saved in a draft. So that saving in a draft, resuming that particular whatever you have texted is possible only because of onPause and onResume states. I hope with this example, it is very clear this onPause and onResume. Then when this onStop will come, when you click on Ohm button, you're running with a particular application and you click on Ohm button, you come to your Ohm screen. But is that app terminated when you click on Ohm button? No, it is not terminated. You can check that app in your list. You have a list button in your Android mobile phone. In list button, you can see all the latest applications which you have loaded. So that complete list is available and once I click on that particular app once again using list, it will go to onRestart and onStart button. So this is possible only because of onRestart state. Then when this app process scale will work, let's say your memory is a limited memory. Only it can save 10 processes. If suppose the 11th process gets loaded, what will happen? One process has to be killed. That decision is taken by operating system to kill any one process to make space for another important processes. This is possible only because of app process scale state. Then when onDestroy will work, if app is present in your list and you swipe, you kill that particular app. How you can kill the app? Either you swipe it left or right, that particular app gets completely removed from your list. That state is nothing but onDestroy. So onDestroy will happen over here and it will app is no more inexistent. Activity will be shut down for that particular application. You can take any example like Gmail, Facebook or you can take any other gaming application. All will have to follow this life cycle process. What are the states in Activity Life Cycle? One important state in Activity Life Cycle is onCreate. What will happen in onCreate? In onCreate, there are certain initiative methods that can be done onCreate. When onCreate is called, your inbox is visible, your messages get loaded. That is possible only because of onCreate. Here, what layout you want is given as an input like here r.layout.mainActivity. So that layout gets loaded or that connection is done in onCreate. You can take any other component also. That text view is accessible only with the help of findView by id. So id is given to that particular text view. Ids are always unique. Now, these are different states which have seen onStart, onResume, onPause. What will happen in onStart? It will make a call to that onStart and the application gets loaded. So that loaded is nothing but it will come in your foreground. Application will come in your foreground and it becomes interactive. What will happen in onResume? Suppose an application is paused. As I said for a mailing application, if a call comes. If an application is paused after some time, something has to happen and the focus will come back. The focus is given back to that particular Gmail application in onResume. Then onPause will happen. Either you pause the video or some video streaming application. If you pause the video or an important priority application will come back. In that case, onPause will work. Now different, these are some more methods or states onStop. OnStop will work. A newly launched activity covers the entire screen. So this onStop will work. It will no more be in existence that particular app. Then onDestroy will completely destroy the app from your memory as well. You can pause the video and give an answer for this particular question. It's an interesting question. In which state the layout.xml is called? You can pause and give the answer. It's onCreate. OnCreate will load this layout.xml file. Coordinated activities, when one activity wants to communicate with another activity. This is possible with callback methods like Activity A is calling Activity B. Activity A will become the root and Activity B will become a chai. When Activity A will call Activity B, Activity A will be onPause. After that Activity B will be loaded. It will follow the Activity life cycle onCreate, onStart, onResume. It will execute. Once Activity B is done with its task, it can come back. Activity A will be loaded and it will call it onStop. This is how coordinating between Activity A and Activity B will take place. This is how Activity to Activity communication happens. These are some of the references. Very good references. You can refer them. Thank you.