Blaze Tama
Blaze Tama

Reputation: 10948

How to access a method by another method?

I was watching thenewboston Android tutorials and I got lost in this line of code:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

I think getWindow() and setFlags() are a method, but why they can be accessed like that? The one that I always see is ClassObject.Method but this time it's Method.Method.

Upvotes: 1

Views: 119

Answers (3)

user
user

Reputation: 87064

It works because the first method(from the activity) returns an object (Window) on which you can call the second method. You could do :

Window obj = getWindow();
obj.setFlags();

if it makes more sense to you.

Upvotes: 1

Soham
Soham

Reputation: 4960

getWindow() returns an object of type Window, on which one can use the setFlags() method

So it is basically a geeky way of writing

Window a = getWindow();
a.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Upvotes: 3

Thommy
Thommy

Reputation: 5407

Because getWindows() is a Method from the Class Activity. And it returns an object from the Class Window which represents your actuall Screen-window.
So setFlags() is actually called on the Window-Class.

Upvotes: 2

Related Questions