Okay.
So now we want to have a look into using an existing instance as an parameter.
So this time we do not create a new one.
But before we make this too complex, let's have look into this one.
So the approach from the last video was the following to create a new POS instance, and we have to
create a new item instance first.
So we did create our item, and based on this one, we provided this to the POS operator.
Then we have our newly created instance over here.
All right?
And this time we want to make it a little bit differently.
So instead of creating a new item, we want to re-use the existing one in this one over here.
Okay.
This might not make that much sense right now, but if you do not think about this application, for
example, about a space pane application, then by doing this over here, we will be able to create
a new player icon on the world so we can take the word instance.
And based on this one, we can provide a new player object on this world instance.
This would be absolutely amazing, right?
Absolutely.
And therefore, we are doing it here theoretically.
And in the next section, you have some exercise regarding to creating a new player on an existing world
object.
All right.
Okay.
Now, it might make more sense.
Okay.
So the things we need to do is we need to scan the memory for this existing item instance.
Then we fetch this one, and then we use this existing item instance as a parameter for our newly created
object.
And this one over here, for example.
So let's see how we can provide an existing instance as in parameter no rocket science, but nevertheless
let's do this.
Okay, so here we are back at Ubuntu VM and now let's have a look into our boss item example over here
in this one.
In this time we want to create a new boss instance, but we do not want to create a new item.
We want to re-use this instance over here.
So therefore these steps we need to do is we need to scan the application memory for this instance and
then we have to create our new post instance with the value we have fetched over here.
That's our alrighty, let's do this.
So let's start a new file over here.
Let's also save this and let's see what's this right now?
This is existing instance parameter that says, okay, let's put this on the right and now let's see
if we can do some speed run over here.
Okay?
And now let's see how we can achieve this over here.
So the first thing, once again, we are dealing with Java code and therefore Java don't perform.
Then we are providing an anonymous function.
In this one.
And here we have now to scan the application memory for our existing item instance and this one over
here.
This has been created in the on create method and this is something we want to find.
So therefore we need to use Java to choose in class reference dot sorry comma and then the callbacks.
Okay.
The class reference.
We need to get the item, so let's click into this one.
Yeah, here we have it.
This is our package name and the class reference is simply just the string.
So package plus the class.
And here once again, double click.
Curly brackets enter on match and function.
Here by having our instance comma on complete function.
Send scanning done.
Okay.
So here we are having now our instance.
And this instance is this one over here.
So the things we need to do is we simply need to create a new post object over here with the same instance
as the parameter.
All right.
How can we do this?
Well, simply getting the class reference,
maybe.
Which class reference?
The post class reference.
And this one over here
shall without the use.
Boss.
And then and let's simply create a new instance, boss instance with the class reference dot, dot,
dot new.
And now we are just forwarding the instance that has been found over here with this instance.
Okay.
And this is how we can create a new instance based on an parameter of an existing instance.
All right, let's comment this real quick and also let's rename this.
And for example, this one is an item instance and then it might become a little bit more clear.
Yes.
Okay.
And then let's see.
Okay.
So here we have the comment at code.
Now let's see if this one works out.
So this time we are not creating a new instance, we are reusing this item.
Instance, if this works, we shouldn't get any error.
And this POS object or this POS instance over here should be created.
We can observe this by add this output over here.
Alrighty.
Okay, let's do this.
So Frieda is still running.
Therefore, all we need to do is we need to get our adb logcat.
And there we have it.
So here we have two windows, little organized.
Let's get back our smartphone.
Let's start this application.
Yes.
Okay, here we have it.
And now let's connect to this process.
Free data issue.
Yes, free data as you come up checking free to instance.
All right.
Let's also keep this in foreground.
Now, let's do this and also have a look on the right.
So we should see the output that the new boss instance has been created.
I'm doing this in three, two, one, go.
Yes, exactly.
A new post instance has been created.
Nice.
We can also see this over here.
No scanning done.
Okay.
So now we know.
Yes.
We do not have to debug output over here.
Shame on me.
But regarding to the output we know.
Okay.
A new post instance has been created.
Now let's scan the application memory regarding to an item.
There should be only one item instance available and then we can be 100% sure that we are reusing this
one over here, not this one.
This one.
All right.
Let's do this really quick.
Slow.
Okay, so now let's do some speed round on this.
So travel to perform.
So back to our Frida output over here.
We can now see.
Yes, only one instance has been found.
Let's execute this once again.
Perfect.
So this means our object is reusing this instance over here.
Nice.
Now we can add our player to the space planning applications so we can have multiple players in our
app right now.
Absolutely.
Amazing, right?
This will be your challenge for the next video.
So I see you there.