 My topic is Android application framework. So most of you have seen this architecture. So I am focusing on how the application framework is intact like native libraries. So JNI bridges the gap between native libraries and activation framework. So first we will see JNI is having a native interface and then Android application framework and the activity manager, content provider, notification manager, resource manager and package manager. So what is Java native interface? So basically it is a part of the course JTK and provide a framework for interfacing the native libraries and codes. And it allows Java code to call C++ functions and C functions and vice versa. So why do we need JNI? Basically the low level devices access are not provided in Java. We cannot access the low level device. So like some system calls, so for accessing those devices we need to implement C++ functions in our Java programming. So one more thing, it increases performance by implementing the rigorous tasks in native languages. So as the assembly languages are low level languages and it obviously improve the low level device access. And we do not need to write the library code again. We can use existing ASL library. So it will also now pros and cons of JNI reuse, allow access to useful native code and it also improve efficiency. We can use any language, whichever CC++ or assembly and the cons is portability, platform dependent because use of C and C++. And extra we need to create serial libraries for implementing JNI. So this is a simple example of JNI. First we have to create a class, this is a hello world example just very easy. First you have to create a class hello world.java and that class first you have to declare a native method and you have to declare only prototype of the method and just call the method in main method. And the system.world library, it loads the hello world library at the dynamic runtime. So this I will explain later how it is happening. Now we have to compile that hello world.java. So it will generate a hello world.class file and one more task we have to generate hello world.h the c-ridder file using java h minus jn and i. So now this is the content of java hello world.h. This is the prototype of the method, print method. This is automatically generated. Now we have to implement the print method in c. So the implementation of print method in c is this. We have to include hello world.h and the print hello world and return. So now we have to compile the c implementation that we have just. So we have to create a shared library, the hello world.so. So further there is a command cc compiler minus shared minus i. You have to include the jdk library and the linux libraries. And just pass the hello world.c and minus o hello world.so this is minus reference output file. And now we have to run the java hello world. Like we have to run the program using java interpreter and the program will print the hello world. So this is just the, so like when it instantiates this hello world, new hello world. So the program generates the, means loads the hello world library, this is the flow chart. Like first you have to create a class, that digression atom method, hello world.so and then we have to compile that class and using that class file we have to generate the header file and then implement the print method in c and compile the c. And that will generate the hello world.dll or so whatever shared library. And then we have to run the program using java interpreter. Now come to the android application framework. So the android framework is a set of APIs that allow developers to quickly and easily write apps for android phones and tablets. So the application framework has the following components, the activity manager, window manager, content manager, package manager, resource manager that manages all the devices and applications. So what is android application? Android application is a consist of one or more components that are defined in application manifest file like when you create android project, there is a file android manifest dot xml and that file you have to define each activity, service, content provided task, whatever you are implemented in your project. So we will see each of them. Activity manager. So activity manager manages the life cycle of application and provide a common navigation back stack. I will come to back on back stack what is it? Activity. So activity is an application component that provides a user interface with which user can interact to do something. So it is just a user interface like when you write a code for activity, it will create a user interface and we can perform any task by calling some service or some other activity. So the application also contains multiple activities that are coupled with each other. So these are the callbacks for activity life cycle. Oncreate says it is called during the life time, activity life time and it says activity is created and it initializes all the resources that is required by the activity. Now all start, execution of the activity can start at any time, system put it on the top of the stack. So your activity now is on the top of stack where you just have to start the activity. So when you on resume, like on resume says activity result to the user and has focus. So like if you playing a song on android phone. So on start means it is just an your user interface is displaying on the phone but the songs is not playing. But on resume your songs is playing and on pause says focus is lost and potentially the activity will set down save data means the focus is lost but means you are switching to some other activity. So the focus is lost but the focus is on to the some other activity. So the duration between on resume and on pause, in that duration the activity is running. So on a stop says activity is no more on the top of a stack. So it is some below the activity, the top activity or anywhere on the start says activity does not exist in the system anymore or the resources granted by the activities can be freed. So this is the activity life cycle. First you have to launch the activity then on create initialize all the resources of the activity and on start it will start the activity now after that on resume. So here the activity is running after on resume and then some another activity comes. So this activity can be paused and goes into the background and here on pause like here I have some activity comes in the foreground and I have paused the grant activity and go to the next activity. Now if the user closes the foreground activity then we return to the same activity again. Now on a stop the activity is stopped and the focus is lost and the focus is gained by some other activity on restore the activities finished and the all resources are freed. So there might be some something wrong with the activity like if some another activity comes and it requires more memory. So it might be killed the background activity like it is not destroyed by the on destroy system. Well it is killed and again when you now when you close the current activity then it will again on create call by call then it will again the whole life cycle is processed. So activities and tasks. So a task is a collection of activities. So this is basically activities in the background and then foreground focus and on and I will come to that later also. So a task is moved to the background as a whole and all its activities is stopped if the user starts new and related tasks. Like task is a collection of activities. So if the activity is stopped and activity is stopped if the select if I started a new task that is not related to the previous task then the activities related to the previous task all are stopped. So it is also possible that different instances of the same activity can be present in different tasks. So like this is the package APK package like the task in context of APK package. So the APK package has a process and the processes have activities, content providers, services. So there might be two or three APK packages like if two applications are want to communicate with each other. So in the context of task there is possible that activity of one application can interact with the activity of another application. So that task may be anything. So intent and intent filters. So intent activates the activities, services and broadcast receivers. So intent basically sends a message to the activity like activate and deactivate the activities and it can be used explicit way or implicit. So implicit way depends on parameters, action, data, MIME to receive other component request. Components it will register filters at activities framework. These like you have to register the components in your project somewhere so that it can receive component request. So when launch an intent object frameworks will match and find the qualified component. So you have registered the components already in activities framework. Now when a request comes it will match the component in the framework and leave them for the users to choose which component to be run. So this is just an example of intent filter like android name, intent accent view, added pick what do you want, the category and the data. Service. Service it is an application component performs long run operation in the background. It does not provide user interface it is running in a background. So it can take two forms started and bound. So when an application component starts it by calling a start service. And bound is when an application component binds to it by calling bind service. So this is the service life cycle. Initially when we call to start service. So there are two life cycles, one for start, one for bound service. So when we call to start service the service is created and on start command it will start working or running. Then the service is stopped by itself or client to client can also stop the service or it can also stop by itself after some time. And the on destruct all back called and the services are down. This is unbounded service, this is bounded service. So now call to bind service. On create the services created after that you have to call on bind that will bind your service to some client or some other application. Then the clients are bound to the service in that area and all clients unbind by calling unbind service. After the unbind you can destroy the service. Example, so like if you are playing a song in your pillar. So pillar internally uses some services for pillar the song. It is like if I develop the application for mp3 player. So I am not writing a code for exactly mp3 player it is use some native library code. So this is the code, how am I access the code it is called the service. So when I play the song the services, the application will bind to the service and when I stop the song and exit the application the application is unbound to the service. That is the back stack. So I previously told you, the activities are arranged in a stack like the back stack in the order in which each activity is opened. So initially we have activity 1 and this is in the foreground like the activity 1 is called another activity, activity 2. So the activity 1 is goes to background and the activity 2 is on the top and it has a focus. Now activity 2 has called another activity, activity 3. So activity 2 goes on the background and activity 3 has a focus and now when activity 3 is destroyed and the focus is upon to the activity 2 it will navigate back. So this is the navigation back stack. So content providers, so content provides enables applications to access data from other applications like we have seen contacts in our mobile. So contacts the application and we will access our contacts through some memory. So this all is done by content providers. So it is the standard interface that connect data in one process and the code running in another process means the process to process communication for data accessing. So content providers exposes a unique URI used to query at an update, delete or delete data. So it provides a URI through which we can query, add, update and delete our data. So the format of URI is like this, a standard prefix, content, the authority part and the path to do determine what kind of data is being requested and a specific record being requested if any. So I will see an example of this. So if we want to show all contacts, so the URI is like this content, call and double slash contacts and people. So this is also the information of all the people. If I want to show people whose ID is one, so we just put the one in front of people. So the first part is content that is always 6, second part is contacts. It may be anything content provider's name. The third part is people like what type of data I want to access. The fourth part is the ID if I want to show a particular record. So this is standard IPC overview. So this is the kernel and the process. Now there is a binder that preaches the gap between kernel and process and that the binder manages the parcel and knows how to access data from parcel and what to do with that data. So the parcel is an interface and that is implemented by bundle and uses intent receivers and activity methods generally. So or you can also create our custom objects for creating our own services or like interaction like activity to activity interaction. So this is just an inter-process communication how it is happening. Marshaling is happening at the parcel. The parcel interface, marshal the data and then pass to the parcel means the marshal data is called as a parcel and then binder knows what to do with parcel and how whatever it is. So IPC parcel labels. A parcel label is a class which can marshal its state to something binder can handle namely a parcel. So this is we have seen. Then the standard Java civilization has semantics parcel labels do not need. So supporting full serialization would mean wasting CPU cycles. So actually the Java serialization needs has semantics and it is a lot more complex. So we cannot use Java serialization here. So that is why we are using parcel labels. Now IPC bundles. So bundles are the type safe containers of primitives. That is C like primitives int, string, etc. So we have a integer or strings. So the bundle will contain all these with their actually it has a methods get, end, put, end, get string, put, string like whatever. So through this it will preserves the type of the data. Then the simple data types passing API uses bundles like think of on-freeze as passing data to your future. So the on-freeze caller I did not mention previously. So it says like when you are doing something like filling a form or just sharing your contact and at that time you receive a call then you need to save the data somewhere. So the on-freeze will do all this. The flat structure permits optimization like memory mapping. So the notification manager, it enables all application to display custom alerts in the status bar. And it can take any like any forms like turning on or flashing LEDs on the device or alerting the user while flashing the backlight, playing the sound, vibrating or just a pop-up window. The resource manager, the providing access to non-code resources such as localized strings, fixed layout files, images, etc. And there is a, it can be two forms of resources, default resources, so to be used at all less of the device configuration and alternative resources designed for use with a specific configuration. So like we have seen a lot of stuff. So that an APK is a binary archive containing compiled albic code and the non-compiled resources such as images, other information for installing the applications like libraries or anything other information. So every APK should be digitally signed. It is not necessary however and it is not mandatory that the signature validated by CA. So these are the references.