Send Parameters To Android Java Code

6 minutes
Share the link to this page
Copied
  Completed
Learn how to send values to Java files.

Transcript

Hello, in this video, I'm going to show you how to actually send parameters to your Java code from your Dart flutter site. So in the previous video, I showed you how to invoke a method from your Java code. And this does return some data mining if you want to send data to it, you can do that it's pretty simple to be fair. So in here, you want to create a variable is equal to a string and the next path can be dynamic. Okay, so this is going to be the key This is going to be the value simple stuff. If you want to learn more about WC map based off of your I recommend that you you know have a look at the dark side all that stuff and I have a separate course.

So feel free to you know, take a look at that. So the key is going to be vol one we can call it whatever We want to highlight about one, and I'm going to pass in the value. Like so, I'm gonna pass it in as a string. So you could pass in number do mathematical calculation, that's totally up to you. We're not gonna be doing that at the next attack, I recommend taking a look at that. Now, that's really all we actually have to do in our dark side, except for the fact that we need to extend this in the map.

And that's it. So we create the map. And as you can imagine, we could have multiple key and value pairs to be able to send multiple parameters in and this part of the need to get updated. Here. What we want to do is first of all we need to import something we need to import java. dot util dot Asterix.

And in here on method code, first of all, what we want to do is say final Map string and this is gonna be the general generally the similar format to this. So dynamic will have its object and this is called arguments this will be equal to method call, got arguments. So we actually have the more now here we've got them all stored in this variable. Now, let's actually you know, handle this in terms of checking a particular value. So, in this printing method, this is where we would want to check for this particular set of values. We are going to say Val one, this variable name can be called wherever you want by Miss keeping it the same.

Equals two we need to cast it but deleted Val one. So we cast what we are going to get there's gonna be arguments dogs, Get an object and we simply put, we have to put the that same name, yes or vow one. And we've got it. Now, this is that parameter. And what I'm going to do is instead of this and say, if Val one dot equals one, then we are going to say result dot set is equal to Yay. And I'm gonna do a simple house.

Same if it's not a value. Yeah, that's it. That's literally all we have to do. Now, we can close it down. So remember, when you're doing native code, hot reload and hot restart will not work. work.

So you will have to shut down the application and then either run it or debug it again, which will, you know, go through the grade or the dependencies, and building the APK and then installing the APK. So you'll get the latest Java side, you're probably not gonna be doing a crazy amount of Java to be fair native code is not the biggest issue, but that's something to bear in mind. So we're almost done. It's just installing now. There we go. So if I click that, we should get yay because we are passed in by one.

Yay. Instead, I pass on the value two. And a simple hot restart should suffice because I'm only changing the dark side and not crushed, I'm gonna have to reload it. Usually a hot restart to a hot reload would suffice simply because I'm only changing the dark side. The flutter side and not the Android native side. So it's installing the APK.

Now it is trying to install it or find some time when it takes this long. Just redoing it will just make the installation part faster. I've just had that issue. And again, it's nothing to do with the native code or any of this stuff that we're doing in this tutorial, just in general little extra tidbit of, you know, advice again that knows promise well now disappeared on this wall no progress in the next few seconds. Okay, so now if I click it, we get right here we get an A, because he wasn't too and that is it. That's all there is if you want to pass in values.

If you have any questions though, feel free to pop me a message. And as usual, I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.