Some Java help with Android source please?

For the Android source Activity.java .

Specifically, the setContentView() method on line 1646:

 public void setContentView(int layoutResID) { getWindow().setContentView(layoutResID); } 

I would like to know what exactly it causes / does.

Here is my trace ...

On line 642, we know that it is the type android.view.Window

 private Window mWindow; 

But Window.java is an abstract class. And on line 738, the method is also abstract:

 public abstract void setContentView(int layoutResID); 

Where is the real body of the function realized?

Back to the Activity.java file, on line 3746 we find some mWindow initializations:

 mWindow = PolicyManager.makeNewWindow(this); mWindow.setCallback(this); ... 

Well, about com.android.internal.policy.PolicyManager makeNewWindow() :

 public static Window makeNewWindow(Context context) { return sPolicy.makeNewWindow(context); } 

and

 private static final IPolicy sPolicy; Class policyClass = Class.forName(POLICY_IMPL_CLASS_NAME); sPolicy = (IPolicy)policyClass.newInstance(); 

IPolicy.java is an interface, which means no implementation at all.

My footprint cannot go further. Could you help me?

In particular, I know that Activity.setContentView() will eventually call android.support.v4.app.Fragment.java Fragment.onInflate() - line 920, Fragment.onAttach() - line 928, Fragment.onCreate() - line 953, Fragment.onCreateView() - line 967 and Fragment.onViewCreated() - line 991.

+4
source share
1 answer

Where is the real body of the function realized?

 private Window mWindow; 

The mWindow command is initialized:

 mWindow = PolicyManager.makeNewWindow(this); 

in the attach () method. Take a look at the PolicyManager.makeNewWindow method in PolicyManager.java.

 Class policyClass = Class.forName(POLICY_IMPL_CLASS_NAME); sPolicy = (IPolicy)policyClass.newInstance(); public static Window makeNewWindow(Context context) { return sPolicy.makeNewWindow(context); } 

And POLICY_IMPL_CLASS_NAME is com.android.internal.policy.impl.Policy . Take a look at Policy.java. Here he is:

 public Window makeNewWindow(Context context) { return new PhoneWindow(context); } 

And setContentView is implemented in PhoneWindow.java

+2
source

Source: https://habr.com/ru/post/1482867/


All Articles