439 App 72 AIDL Android Interface Definition Language

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi students in this tutorial I want to talk about a IDL Android interface language definition so now let's create a new Android studio project and for the application name just step in here app 72 - hey I DL so you can specify the company domain package name and the project location and then click on next and here choose API 16 Android 4.1 jelly bean and then we'll connect and here choose empty activity next and here we don't have to change anything and then click on finish so now that our project is actually created let's go to let's first design the user interface of our application so go to enjoy this res folder layout and then double double click on this activity underline minute XML so here let's delete this hello world text view here and now let's actually drag through a text fields inside this layout so at the bottom first click click on this text hub and change this relative layout to linear layout and now let's specify the orientation of this layout so orientation vertical so let's go to design tab and now let's drag two text fields so inside this text fields folder just select this number right right select this one and just drag it here into this linear layout vertical let's actually drag another a text field so again select this number and just drag it here so now we have to edit text here write two text fields so just select this one the first one and let's specify the ID so for the ID just type in here ADT first number and the person enter key on your keyboard and for the status second edit text here selected and for the ID just type in here ADT second number right and then press on Enter key on your keyboard so now let's actually drag a button into this layout so inside this widget folder select this button and just drag it here and put it here below this edit X here just select this button and for the idea just type in here bt bt n multiplied billion multiplied and then press on Enter key on your keyboard and for the texture type in here let's select the text attribute and just type in here a multiply multiply and then press the Enter key on your keyboard so now let's actually just drag a text view so just select this text view here and put it here below this button and select this text view and for the idea just type in here THD multiply result txt multiply result and then press on Enter key on your keyboard and just delete this value for the text attribute of this text view so now we actually designed the user interface our application so now I will talk about a idea so first let's see how we can actually create a ideally in Android so just select this app folder so make sure that you are inside the Android view right so if you just click on these two little triangles here make sure that you have selected Android and select this app folder at the top click on file new and then just here you can see this a idea right so just click on a IDL file and here you can actually specify the interface name so for the interface name we can say for example here the default name is I my ID a IDL interface I think it's good this is actually an interface and other classes can implement this interface can conform to this interface so that they can actually use the functionalities of this interface so let's just name it multiply multiply interface and the target source is main so just click on finish so now as you can see inside this app folder we have another folder called a IDL and inside this folder we have our package right and inside this package we have this file multiplied interface that a IDL so look at this comment here it says demonstrates some basic types that you can use as parameters and return values in a IDL right so here you can see these types is as you can see this is actually a method basic types these are the types in integer lank boolean float double and string so let's actually delete this comment and this method here so here as you can see we have an interface right interface multiply interface right so let me tell you that a IDL is used for actually creating a relationship between the client and the remote server right so for example the main activity is the client and the server is going to be the class that is actually playing the role of a server service let me show you an example here and an inn it will completely makes sense right by showing you by creating a real application you can actually understand what is a ideal used for so now inside this interface inside the curly braces of this interface let's write some codes so now as at the name of our interface suggests this is going to be an interface for multiplying values right so here I am going to declare a method for that is actually going to use for multiplying values so here I can say int so this is going to be the return type of my method right and here I can say multiply multiply two values two values together and then here I can just put a pair of parentheses so this method is going to accept some parameters to my parameters actually so the first parameter is going to be of type integer so int and here I can say first number comma int so this is going to be the second parameter second number and then because this is actually an interface and you are already familiar with interfaces in Java you cannot provide a body for this method this is going to be a declaration of this method so we just need to put semicolon at the L at the end of our statement here right we just declared this method we do not provide implementation here inside this interface so now let's actually create a service so at the top just click on file first let's go to view here so at the top just click on a view and then tool windows and then click on project right and now we want to actually create a service that implements this interface that implements this a IDL here and then we can actually use that service so let's actually select this Java folder here just open it and then select this package and at the top just click on file new and then click on service just select a service here so this is the service right and then here we have two options service and the second one is service intent service so select this one service here and for the class name so this is going to be a class right so here I can say multiplication multi application service so this is the name on what the name of my service right and then click on finish so now we have a new class and the name of this class is multiplication service right so you can see that this is a public class and this class extends the service class so in the inside this class we have this empty constructor that is actually already provided for us by Android and we have this method that is overrated here and as you can see the same if this method is actually unbind that returns a value of type I binder right so now let's see how we can use this method so like here this comment is it says return the communication channel to the service right so now let's just double click on this tab here this multiplication service touch of a tab in order to make this area wider first let's actually delete these two lines of code here and now I am inside this method right first of all whenever that you actually create an a IDL file so now let me show you that while here view tool windows and then project so inside our project we have this a ideal file right with the extension dot a IDL file whenever that you create a file that is actually has the extension a IDL you must actually build your project so at the top click on build and here you have two options clean project and rebuild project so when you choose rebuild project it's gonna first clean your project and then it's going to build your project so it's better to choose this option rebuild project so just select it and as you can see at the bottom it says Gradle build running so let's wait a little bit here so now as you can see it's actually running the project so now everything is OK right and now my project is actually built so now let's go inside this method unbind you look at the return type of this method I binder so here we must return a value of type I binder right so here first let's put the state a statement here so just type in here return return my binder semicolon return my binder so this is going to be the returned value but as you can see we have an error and this means that we haven't still created this return value so now let's actually make this tab to just double click on this tab here in order to make this area wider and let's go inside the curly braces of this Clapp class multiplication service right so after the ending curly brace of this method unbind and before the ending curly brace of this class so inside this class just type in here so the name of our a IDL file is actually multiply multiply interface so here we want to create an object of type Ib in the right so in order to do that first refer to the name of your a IDL file multiply interface dot stop this is very important stop with capital S and now we can actually name a name or object we can give a name to our object so the name is going to be this name right my binder so here I can say my pointer assignment operator so now let's create an object so here we are actually just creating a variable of type multiply interface that stopped right so now let's create the actual object so in order to do that first you need to put the new keyboard and then you just you just need to put you just need to refer to your interface here to your a ideal file multiply interface so when you put the capital m here it's gonna actually at the autocomplete feature of Android studio is going to help you to choose this option stop write stop with capital S and inside the curly braces where you can see this dot dot dot so select this one and then press the Enter key on your keyboard so now the autocomplete feature of Android studio put these lines of code here for you automatically so here we have an error and after the ending curly brace here just put a semicolon so now the error is gone so now here let's let me create a new line so that you can ASSU you can actually the whole method here you can see the whole method here so now we have actually override it up we have we have a new override method and the access modifier of this method is public the return type of this method is integer and the name of this method is multiply two values together so as you can see we have actually a typo let's go to our multiply interface that a IDL so as you can see I did I did a mistake and instead of you I put Y so let's just delete this Y and put you multiple multiply two values together so let's go to our a service multiplication service and now let's actually change this one to you so because we actually changed our a IDL file again we must just build our projects so at the top just click on build and then select rebuild project so let's wait a little bit here and now everything is fine right we have no errors here so here we have this method multiply two values together and this method accepts two arguments the first one is of the integer first number and the second one is of type integer second number right so now as you can see this method throws an exception so when we want to actually use this method when our main activity want to use this method we actually handle this a exception so this method by default returns a value of type integer which is zero so we don't want this statement here just delete it and now as its name suggests multiply two values together I can say return so now this method accepts two parameters right so I can refer to the name of this first number first number multiplied by second number so now you can see that this service is actually implementing this interface this multiply interface that AI DL right so we created an a a IDL file here and as you can see this is actually just a simple interface right and you are already familiar with interfaces in Java and we created a service which is this one multiplication service and this service is actually implementing this interface so that we can actually provide an implementation for them for the method of this interface so now we have this method here and this service as you can see we have actually an overrated method and this service needs to return a value of type I bind I binder right so we just returned this my binder here so now let's go to our main activity here so this is going to be our the client right so now we can actually just interact with the remote service right so we have actually an interface and we have a service and we have a client which is the main activity and the main activity can interact with the remote service by using this a IDL file this multiplied inter interface that they ideal so that's the whole concept of the ideal in Android write Android interface language definition write a IDL and that's the whole concept and now you can actually figure out what's going on here so let's go to our main activity and let's see how we can use this service so first of all let's actually just a declare this the objects the user interface components that we put here so we have to edit X we have a button and we have a textview so let's go to main activity and so this class here and first I can say that edittext so here I can say it ET first number unity first number so I can actually declare my two objects which are of type edit X in just one line so comma ADT second number right semicolon and then we have actually a button so button BTN multiply semicolon and we have a textview so textview txt multiply multiply result txt multiply result semicolon so now let's go inside this method oncreate right and now let's initialize these objects that we actually declared inside our class so the first one is edited first number assignment operator and the minute we cast this object one edittext object find view by ID or that ID dot e dt first number semicolon EDT second number assignment operator let's cast this object to an edit text object find view by ID or dot ID dot e dt second number semicolon and we have this button BTN multiply so BTN multiply assignment operator let's cast this object to a button object find view by ID or that ID dot b TN x : and we have tht multiply result so txt multiply result assignment operator let's that cast this object to a textview object find view by ID or that ID dot txt multiply result right so now everything is fine everything is okay so now let's see how we can use this service so first of all let's create a listener for this spot and BTW and multiply so whenever the user clicks on this button this button something is going to happen so here I'm going to actually implement the view that onclick listener interface so class main activity extends app compat activity implements view dot unclick listener so now here inside is uncreated method here I can say BTN a multiplied that set unclick listener and then here I I need to pass the context so the context is main activity dot this and then here inside the class inside this main activity class we must actually provide an implementation for the unclick method that is that is inside of this view that unclick listener interface so inside this class I can just say unclick and here unclick and now the autocomplete feature of Android studio is helping me to choose this method and then press the Enter key on your keyboard so now we have this method here inside this class so let's go to our uncreate method and here we have actually a method called bind service so now we may want to ask ourselves what we want to do here we want to bind this our main activity this client of with this service so we want to use this method point service right so now let me show you what are the arguments of this method the first argument is going to be of type service right and as you can see the first one is actually of that intent and the name is service so we need to pass the Internet and the second argument is a service connection and the third argument is actually flags which is of type integer so if we need to pass these arguments to this method so that we can use this method so let's see how we can do that first let's actually create the in the intent as you can see here so before the declaration before use before calling this method bind service we need to actually create the intent so let's do that here so here I can say intent intent right and the name is going to be multiplied intent multi multiply intent assignment operator and then here as you see we are just creating a variable of type intent and the name is multiply intent so now we want to create the actual object of intent right so here I just put new and then I I can just say intent and this method actually did the construe factor of intent needs two arguments first we need to pass the context so here I can say main activity that this comma and the second argument is going to be the service right so if I actually hover over this point service here it says the first argument is actually a Feb intent but the name is service so we already created this multiplication service here right so for the second argument I can pass this multiplication service here so I can say multiplication service dot class semicolon right so now you know that why we actually are created this service because we want to bind this main activity this client with the service right and now we pass this multiplication service here so now we have the first argument multiplied in 10 so here I can say multiply in tenth comma or I can say multiply service it's better to actually put multiply service it's more meaningful multiply service so let's change this one to multiply service so now we need to specify the second argument so the second argument is actually a service connection right so let's actually create an object of type service connection inside this main activity class so after the ending curly brace of this method oncreate and inside this main activity class I'm going to create actually an object of type service connection here so here I can say service connection service connection and the name is going to be my service connection my service connection and then I put an assignment operator here and then I'll put the new keyboard and here I want to use I actually want to create an anonymous inner class so let me tell you that this service connection is not a class this is just an interface so let's let me just hold the command key on on our keyboard and then click on the service connection here as you can see this is not a class this is an interface here with these methods on service connected and an service disconnected right so we want to actually use this interface so now here I am going to create an anonymous inner class that actually conforms to this interface that implements this interface so here I can say new and then I hold the shift key on my keyboard and then I actually present the S key on my keyboard so now it's you can see that the autocomplete of the autocomplete feature of Android studio is helping me to choose this option service-connection right as you can see you can see these curly braces so choose this one and then press the Enter key on your keyboard so now you can see that the Android studio provided this codes here for me automatically so now we need to put a semicolon at the end of this curly brace here after the ending curly brace and now everything is fine so we have actually an anonymous inner class that conforms or implements this service connection and we have these two methods here override it for us so we must actually provide an implementation for these methods because this is an interface so now inside this on service connected so we want to use this method on service connected right inside this method we need to put a logic so now first of all let's create a variable of type multiply interface inside our class so let's actually scroll to the top and inside this main activity class here I can just create a variable of type multiply interface so here I can say multiply interface let's actually give this variable a name right so that the data type is multiply interface and here I can say my interface right my interface semicolon so now let's actually scroll down here so here we just declare this variable right my interface now let's scroll down here and let's go inside this one service connected and now let's initialize this variable so here I can say my interface assignment operator so look at this method here on service connected this method accepts two parameters the first one is component name and the second one is eye binder so we want to use this I binder here because we want to actually appoint this client main activity with the interface right with this service so now let's actually just type in here a multi-planet actually differ refer to the name of this interface multiplied interface ADL so here I can say multiplied interface multiplied interface dot stopped here and then here I can say dot as interface and this method actually needs an argument of type I binder so we actually get this I binder from this method from this Unseld with connected methods so here again I pass this I binder to this method so here I can say I binder semicolon so by using this service connection we are actually connecting these service this multiplication service to this interface we have the second argument of this point service method so the second argument is my service connection so we created this one here right and we need to actually provide the thread argument so the third argument is of type integer and it is actually the flag so here I can say so now as you can see our I actually so I mistakenly deleted the name of this variable so let me actually undo this action so I put this name here so now we have my service connection right so I can put the comma here and now we need to specify the third argument right and now that the federal limit is of type integer so it is actually going to be context so this is going to be the flag so we must put a flag here so here I can say context dot and here we actually choose this one point auto create right bind Auto create this is very important this is the flag that we use so it's going to bind this service with that interface so just put a semicolon at the end of your statement right so now we have this point service here for us so it's going to do the job for us and we pass these arguments multiply service so this is the intent and then we have the service connection and then we actually pass this fly context that point auto create so now the binding is actually implemented here so let's go to this unclear each method here so first of all let's actually just as you can see we have these Eddy texts here right so if we want to get the divide the value of this Eddy text and this one and then if we want to multiply these two values together and then when the user clicks on this button it the result is going to be shown here on this txt multiply result so let's go trees to this uncreate method and here I can create a variable of type integer and the name of this variable is going to be first number first number and then I put an assignment operator here and in here I can say EDT first number dot get text dot two string semicolon so now as you can see we have an error and because this is actually an integer variable here we are getting a string value so we want to test this value we want to just a convert actually this value to an integer value so we use the method of the integer class so integer dot parse int so you are already familiar with this method and this method accepts an argument of type string and it's going to convert this value to an integer value here so we actually put this value inside the parentheses so inside the parentheses of this parseint method and now the error is gone let's create another variable int second number assignment operator so integer dot parseint idiot is second number that get takes the two string semicolon so now let's create another variable so int result assignment operator so let me scroll to the top here you can see this interface here my interface so we can actually access the method that we have inside this a IDL file this one and we actually provided an implementation for this method inside this service so inside this main activity class and inside this onclick method we actually pointed this service with this client here so we created a connection between this service as you can see we provided this my service connection here right so it's going to create a connection between the service and this I ideal file and now this service this my interface here is now initialized right so we declared this variable my interface and we initialize this variable here inside this answer is connected right so now we have this my interface here so int result assignment operator and here I can refer to this my interface and now I can say dot multiply two values together so now I can pass two arguments to this method so the first one is going to be for example the first number so we get this value from the first actually edittext so first number we have a typo here so first number and we need to pass the second argument so second number semicolon right so now we have actually an error so let me show you what is this error let's actually hover over this error here and says unhandled exception android OS that remote exception so now let me show you why we have this exception so let's go to this a IDL file as you can see we declared this method here right but we provided an implementation for this method inside this multiplication cell with the Java so here look at this piece of code here inside this block of code you can see that we actually override this method multiply two values together so we get this method from this interface multiply interface and now you can see that this method actually throws an exception this is very important so because this method froze and exit an exception and and it is called a remote exception we actually must handle this exception otherwise the compiler is not gonna allow us to run our application so let's go to main activity here and inside this onclick method here before this line of code here I can actually just type in try I can provide a try block here I can try and then put a catch block and then here inside the parentheses of this catch here I can say a remote exception so you know what is the name of that exception right so because inside this cell multiplication service that Java you can see the name of this exception so let's go to this main activity - over here and instead is onclick method so the type is the remote exception and the name is e right and here I can just open and close this cache black by using these curly braces and here let's just select this line I've got here and just cut this line of code and just paste this line of code here inside this try block right and now the error is gone so now we have this variable int result my interface that multiply two values together and now we are actually handling this exception because we put it inside this try block so we can actually just print the so here I can say eat a dot print stack trace right so we can adjust our print these values to the large later when I actually an error occurs so we have this variable and here I can insert this stripe like I can say txt multiply result the set text and here I can refer to the name of this variable result but because this is actually an integer value and this method needs our variable a value of the extreme I can convert this value to a string value by just putting a plus operator and then put our two double quotes here so now let's run our project and see what happens let me show you the emulator so now as you can see here my application is running on this emulator so now we need to provide the first values so the first value is going to be number 10 and the second value is going to be number for example again 10 so let's click on this button and we have number 100 so let's change the first value to 5 and the second value to number 2 right let's click on this button again and now we have number 10 or let's change the first value to number 3 and click on this button now we have number 6 so now you can see that how we used this a IDL in Android so I think now we can actually figure out how to use a I deal in Android and if you have any questions about these concepts that I taught you in this lesson please watch the discussion in the course and then I do my best to answer all of your questions thank you very much for watching and I'll see you in the next tutorial
Info
Channel: Technical Hacker
Views: 1,973
Rating: 4.7837839 out of 5
Keywords: how, to, hack, web, site, bangladesh, black, hat, hackers, bangla, হ্যাকিং, শিখার, বই, পৃষ্ঠা, নেভিগেশন, hacking, software, apps, tutorials, tricks, tools, course, for, windows, 10, download, facebook, hacker, v.2.9.0, (latest, version), phone, apk, wifi, professional
Id: g07hMnO5e9Q
Channel Id: undefined
Length: 33min 14sec (1994 seconds)
Published: Sat Apr 06 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.